Fixed issue 582: set the right construct stub for native functions.
authorvitalyr@chromium.org <vitalyr@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 19 Jan 2010 10:32:20 +0000 (10:32 +0000)
committervitalyr@chromium.org <vitalyr@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 19 Jan 2010 10:32:20 +0000 (10:32 +0000)
TEST=cctest/test-api/NativeFunctionConstructCall
BUG=582

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

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

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

index 4090a08..3ae8577 100644 (file)
@@ -1868,8 +1868,10 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) {
   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
index f948cd3..7e67c00 100644 (file)
@@ -2788,6 +2788,10 @@ static const char* kExtensionTestScript =
 
 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();
 }
 
@@ -2829,6 +2833,21 @@ THREADED_TEST(FunctionLookup) {
 }
 
 
+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;
 static const char* last_message;
 void StoringErrorCallback(const char* location, const char* message) {