diff --git a/src/api.cc b/src/api.cc index 6ff2bd69eb..f8bd63f482 100644 --- a/src/api.cc +++ b/src/api.cc @@ -979,6 +979,12 @@ void ObjectTemplate::SetInternalFieldCount(int value) { "Invalid internal field count")) { return; } + if (value > 0) { + // The internal field count is set by the constructor function's + // construct code, so we ensure that there is a constructor + // function to do the setting. + EnsureConstructor(this); + } Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value)); } diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index d70fd8e8e0..a550e5ea36 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -4825,3 +4825,21 @@ THREADED_TEST(DisposeEnteredContext) { inner->Exit(); } } + + +// Regression test for issue 54, object templates with internal fields +// but no accessors or interceptors did not get their internal field +// count set on instances. +THREADED_TEST(Regress54) { + v8::HandleScope outer; + LocalContext context; + static v8::Persistent templ; + if (templ.IsEmpty()) { + v8::HandleScope inner; + v8::Handle local = v8::ObjectTemplate::New(); + local->SetInternalFieldCount(1); + templ = v8::Persistent::New(inner.Close(local)); + } + v8::Handle result = templ->NewInstance(); + CHECK_EQ(1, result->InternalFieldCount()); +}