Revision: 3643
Author: [email protected]
Date: Tue Jan 19 02:32:20 2010
Log: Fixed issue 582: set the right construct stub for native functions.

TEST=cctest/test-api/NativeFunctionConstructCall
BUG=582

Review URL: http://codereview.chromium.org/551063
http://code.google.com/p/v8/source/detail?r=3643

Modified:
 /branches/bleeding_edge/src/parser.cc
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/src/parser.cc       Tue Jan 12 09:22:57 2010
+++ /branches/bleeding_edge/src/parser.cc       Tue Jan 19 02:32:20 2010
@@ -1868,8 +1868,10 @@
   Handle<JSFunction> fun = Utils::OpenHandle(*fun_template->GetFunction());
   const int literals = fun->NumberOfLiterals();
   Handle<Code> code = Handle<Code>(fun->shared()->code());
+ Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub());
   Handle<JSFunction> boilerplate =
       Factory::NewFunctionBoilerplate(name, literals, code);
+  boilerplate->shared()->set_construct_stub(*construct_stub);

   // Copy the function data to the boilerplate. Used by
   // builtins.cc:HandleApiCall to perform argument type checks and to
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Fri Jan 15 04:25:24 2010
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Tue Jan 19 02:32:20 2010
@@ -2788,6 +2788,10 @@

 static v8::Handle<Value> CallFun(const v8::Arguments& args) {
   ApiTestFuzzer::Fuzz();
+  if (args.IsConstructCall()) {
+    args.This()->Set(v8_str("data"), args.Data());
+    return v8::Null();
+  }
   return args.Data();
 }

@@ -2827,6 +2831,21 @@
   CHECK_EQ(v8::Integer::New(7), Script::Compile(v8_str("Foo(1)"))->Run());
   CHECK_EQ(v8::Integer::New(6), Script::Compile(v8_str("Foo(2)"))->Run());
 }
+
+
+THREADED_TEST(NativeFunctionConstructCall) {
+  v8::RegisterExtension(new FunctionExtension());
+  v8::HandleScope handle_scope;
+  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());
+}


 static const char* last_location;
-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to