Change Context::New to not create persistent handles.

This moves the responsibility of putting a new context into a persistent
handle to the embedder. Also it removes one API function where the copy
constructor for persistent handles is needed.

R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/13799003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14203 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 996a80df
......@@ -3867,11 +3867,11 @@ class V8EXPORT Context {
*/
void ReattachGlobal(Handle<Object> global_object);
/** Creates a new context.
/**
* Creates a new context and returns a handle to the newly allocated
* context.
*
* Returns a persistent handle to the newly allocated context. This
* persistent handle has to be disposed when the context is no
* longer used so the context can be garbage collected.
* \param isolate The isolate in which to create the context.
*
* \param extensions An optional extension configuration containing
* the extensions to be installed in the newly created context.
......@@ -3885,6 +3885,14 @@ class V8EXPORT Context {
* template. The state of the global object will be completely reset
* and only object identify will remain.
*/
static Local<Context> New(
Isolate* isolate,
ExtensionConfiguration* extensions = NULL,
Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
Handle<Value> global_object = Handle<Value>());
/** Deprecated. Use Isolate version instead. */
// TODO(mstarzinger): Put this behind the V8_DEPRECATED guard.
static Persistent<Context> New(
ExtensionConfiguration* extensions = NULL,
Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
......
......@@ -4863,18 +4863,14 @@ static i::Handle<i::FunctionTemplateInfo>
}
Persistent<Context> v8::Context::New(
static i::Handle<i::Context> CreateEnvironment(
i::Isolate* isolate,
v8::ExtensionConfiguration* extensions,
v8::Handle<ObjectTemplate> global_template,
v8::Handle<Value> global_object) {
i::Isolate::EnsureDefaultIsolate();
i::Isolate* isolate = i::Isolate::Current();
EnsureInitializedForIsolate(isolate, "v8::Context::New()");
LOG_API(isolate, "Context::New");
ON_BAILOUT(isolate, "v8::Context::New()", return Persistent<Context>());
i::Handle<i::Context> env;
// Enter V8 via an ENTER_V8 scope.
i::Handle<i::Context> env;
{
ENTER_V8(isolate);
v8::Handle<ObjectTemplate> proxy_template = global_template;
......@@ -4929,10 +4925,43 @@ Persistent<Context> v8::Context::New(
}
// Leave V8.
if (env.is_null()) {
return Persistent<Context>();
}
return Persistent<Context>(Utils::ToLocal(env));
return env;
}
Persistent<Context> v8::Context::New(
v8::ExtensionConfiguration* extensions,
v8::Handle<ObjectTemplate> global_template,
v8::Handle<Value> global_object) {
i::Isolate::EnsureDefaultIsolate();
i::Isolate* isolate = i::Isolate::Current();
Isolate* external_isolate = reinterpret_cast<Isolate*>(isolate);
EnsureInitializedForIsolate(isolate, "v8::Context::New()");
LOG_API(isolate, "Context::New");
ON_BAILOUT(isolate, "v8::Context::New()", return Persistent<Context>());
i::HandleScope scope(isolate);
i::Handle<i::Context> env =
CreateEnvironment(isolate, extensions, global_template, global_object);
if (env.is_null()) return Persistent<Context>();
return Persistent<Context>::New(external_isolate, Utils::ToLocal(env));
}
Local<Context> v8::Context::New(
v8::Isolate* external_isolate,
v8::ExtensionConfiguration* extensions,
v8::Handle<ObjectTemplate> global_template,
v8::Handle<Value> global_object) {
i::Isolate::EnsureDefaultIsolate();
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
EnsureInitializedForIsolate(isolate, "v8::Context::New()");
LOG_API(isolate, "Context::New");
ON_BAILOUT(isolate, "v8::Context::New()", return Local<Context>());
i::HandleScope scope(isolate);
i::Handle<i::Context> env =
CreateEnvironment(isolate, extensions, global_template, global_object);
if (env.is_null()) return Local<Context>();
return Utils::ToLocal(scope.CloseAndEscape(env));
}
......
......@@ -303,14 +303,11 @@ Handle<Context> Bootstrapper::CreateEnvironment(
v8::ExtensionConfiguration* extensions) {
HandleScope scope(isolate_);
Genesis genesis(isolate_, global_object, global_template, extensions);
if (!genesis.result().is_null()) {
Handle<Object> ctx(isolate_->global_handles()->Create(*genesis.result()));
Handle<Context> env = Handle<Context>::cast(ctx);
if (InstallExtensions(env, extensions)) {
return env;
}
Handle<Context> env = genesis.result();
if (env.is_null() || !InstallExtensions(env, extensions)) {
return Handle<Context>();
}
return Handle<Context>();
return scope.CloseAndEscape(env);
}
......
......@@ -874,8 +874,9 @@ bool Debug::Load() {
// Check for caught exceptions.
if (caught_exception) return false;
// Debugger loaded.
debug_context_ = context;
// Debugger loaded, create debugger context global handle.
debug_context_ = Handle<Context>::cast(
isolate_->global_handles()->Create(*context));
return true;
}
......@@ -891,7 +892,7 @@ void Debug::Unload() {
DestroyScriptCache();
// Clear debugger context global handle.
Isolate::Current()->global_handles()->Destroy(
isolate_->global_handles()->Destroy(
reinterpret_cast<Object**>(debug_context_.location()));
debug_context_ = Handle<Context>();
}
......
......@@ -68,8 +68,11 @@ void CcTest::InitializeVM(CcTestExtensionFlags extensions) {
EXTENSION_LIST(CHECK_EXTENSION_FLAG)
#undef CHECK_EXTENSION_FLAG
if (context_.IsEmpty()) {
v8::Isolate* isolate = default_isolate();
v8::HandleScope scope(isolate);
v8::ExtensionConfiguration config(extension_count, extension_names);
context_ = v8::Context::New(&config);
v8::Local<v8::Context> context = v8::Context::New(isolate, &config);
context_ = v8::Persistent<v8::Context>::New(isolate, context);
}
context_->Enter();
}
......
......@@ -695,7 +695,7 @@ TEST(ExistsInHiddenPrototype) {
class SimpleContext {
public:
SimpleContext() {
context_ = Context::New(0);
context_ = Context::New();
context_->Enter();
}
......
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