Fix issue 582: preserve construct stub on first allocation in case we can't optimize it.
authorvitalyr@chromium.org <vitalyr@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 20 Jan 2010 14:43:12 +0000 (14:43 +0000)
committervitalyr@chromium.org <vitalyr@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 20 Jan 2010 14:43:12 +0000 (14:43 +0000)
BUG=582
TEST=cctest/test-api/NativeFunctionConstructCall

Review URL: http://codereview.chromium.org/546088

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3659 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/runtime.cc
test/cctest/test-api.cc

index b6da528..7d1504e 100644 (file)
@@ -4782,7 +4782,7 @@ static Code* ComputeConstructStub(Handle<SharedFunctionInfo> shared) {
     return Code::cast(code);
   }
 
-  return Builtins::builtin(Builtins::JSConstructStubGeneric);
+  return shared->construct_stub();
 }
 
 
index 7e67c00..8403ad1 100644 (file)
@@ -2839,12 +2839,16 @@ THREADED_TEST(NativeFunctionConstructCall) {
   static const char* exts[1] = { "functiontest" };
   v8::ExtensionConfiguration config(1, exts);
   LocalContext context(&config);
-  CHECK_EQ(v8::Integer::New(8),
-           Script::Compile(v8_str("(new A()).data"))->Run());
-  CHECK_EQ(v8::Integer::New(7),
-           Script::Compile(v8_str("(new B()).data"))->Run());
-  CHECK_EQ(v8::Integer::New(6),
-           Script::Compile(v8_str("(new C()).data"))->Run());
+  for (int i = 0; i < 10; i++) {
+    // Run a few times to ensure that allocation of objects doesn't
+    // change behavior of a constructor function.
+    CHECK_EQ(v8::Integer::New(8),
+             Script::Compile(v8_str("(new A()).data"))->Run());
+    CHECK_EQ(v8::Integer::New(7),
+             Script::Compile(v8_str("(new B()).data"))->Run());
+    CHECK_EQ(v8::Integer::New(6),
+             Script::Compile(v8_str("(new C()).data"))->Run());
+  }
 }