Revision: 14203
Author: [email protected]
Date: Wed Apr 10 02:34:37 2013
Log: 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.
[email protected]
Review URL: https://codereview.chromium.org/13799003
http://code.google.com/p/v8/source/detail?r=14203
Modified:
/branches/bleeding_edge/include/v8.h
/branches/bleeding_edge/src/api.cc
/branches/bleeding_edge/src/bootstrapper.cc
/branches/bleeding_edge/src/debug.cc
/branches/bleeding_edge/test/cctest/cctest.cc
/branches/bleeding_edge/test/cctest/test-decls.cc
=======================================
--- /branches/bleeding_edge/include/v8.h Tue Apr 9 00:34:32 2013
+++ /branches/bleeding_edge/include/v8.h Wed Apr 10 02:34:37 2013
@@ -3867,11 +3867,11 @@
*/
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 @@
* 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>(),
=======================================
--- /branches/bleeding_edge/src/api.cc Tue Apr 9 00:34:32 2013
+++ /branches/bleeding_edge/src/api.cc Wed Apr 10 02:34:37 2013
@@ -4863,18 +4863,14 @@
}
-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 @@
}
// 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));
}
=======================================
--- /branches/bleeding_edge/src/bootstrapper.cc Thu Apr 4 05:10:23 2013
+++ /branches/bleeding_edge/src/bootstrapper.cc Wed Apr 10 02:34:37 2013
@@ -303,14 +303,11 @@
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);
}
=======================================
--- /branches/bleeding_edge/src/debug.cc Thu Mar 21 09:12:50 2013
+++ /branches/bleeding_edge/src/debug.cc Wed Apr 10 02:34:37 2013
@@ -874,8 +874,9 @@
// 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 @@
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>();
}
=======================================
--- /branches/bleeding_edge/test/cctest/cctest.cc Wed Apr 10 01:29:39 2013
+++ /branches/bleeding_edge/test/cctest/cctest.cc Wed Apr 10 02:34:37 2013
@@ -68,8 +68,11 @@
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();
}
=======================================
--- /branches/bleeding_edge/test/cctest/test-decls.cc Fri Mar 15 05:06:53
2013
+++ /branches/bleeding_edge/test/cctest/test-decls.cc Wed Apr 10 02:34:37
2013
@@ -695,7 +695,7 @@
class SimpleContext {
public:
SimpleContext() {
- context_ = Context::New(0);
+ context_ = Context::New();
context_->Enter();
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.