Commit db1896c2 authored by ager@chromium.org's avatar ager@chromium.org

Make sure that the prototype of the initial map is created in the

right context.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1157 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2de5de49
......@@ -1724,9 +1724,12 @@ Object* Heap::InitializeFunction(JSFunction* function,
Object* Heap::AllocateFunctionPrototype(JSFunction* function) {
// Allocate the prototype.
Object* prototype =
AllocateJSObject(Top::context()->global_context()->object_function());
// Allocate the prototype. Make sure to use the object function
// from the function's context, since the function can be from a
// different context.
JSFunction* object_function =
function->context()->global_context()->object_function();
Object* prototype = AllocateJSObject(object_function);
if (prototype->IsFailure()) return prototype;
// When creating the prototype for the function we must set its
// constructor to the function.
......
......@@ -5607,3 +5607,36 @@ THREADED_TEST(DictionaryICLoadedFunction) {
CompileRun("for (var j = 0; j < 10; j++) RegExp('')");
}
}
// Test that cross-context new calls use the context of the callee to
// create the new JavaScript object.
THREADED_TEST(CrossContextNew) {
v8::HandleScope scope;
v8::Persistent<Context> context0 = Context::New();
v8::Persistent<Context> context1 = Context::New();
// Allow cross-domain access.
Local<String> token = v8_str("<security token>");
context0->SetSecurityToken(token);
context1->SetSecurityToken(token);
// Set an 'x' property on the Object prototype and define a
// constructor function in context0.
context0->Enter();
CompileRun("Object.prototype.x = 42; function C() {};");
context0->Exit();
// Call the constructor function from context0 and check that the
// result has the 'x' property.
context1->Enter();
context1->Global()->Set(v8_str("other"), context0->Global());
Local<Value> value = CompileRun("var instance = new other.C(); instance.x");
CHECK(value->IsInt32());
CHECK_EQ(42, value->Int32Value());
context1->Exit();
// Dispose the contexts to allow them to be garbage collected.
context0.Dispose();
context1.Dispose();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment