From 7df10557a57bb0c3e5e0bf832ec2ac4e6b664a96 Mon Sep 17 00:00:00 2001 From: "jochen@chromium.org" Date: Tue, 12 Nov 2013 11:44:58 +0000 Subject: [PATCH] Add explicit Isolate parameter to External::New We can't deprecate the non-Isolate version yet but soon will. R=svenpanne@chromium.org, svenpanne@google.com BUG=266838 Review URL: https://codereview.chromium.org/70163002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17638 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 2 ++ samples/process.cc | 4 ++-- src/api.cc | 17 +++++++++----- test/cctest/test-accessors.cc | 21 +++++++---------- test/cctest/test-api.cc | 51 ++++++++++++++++++++-------------------- test/cctest/test-cpu-profiler.cc | 12 ++++++---- test/cctest/test-decls.cc | 2 +- 7 files changed, 59 insertions(+), 50 deletions(-) diff --git a/include/v8.h b/include/v8.h index 1f8cbfd..5ab77eb 100644 --- a/include/v8.h +++ b/include/v8.h @@ -3042,6 +3042,8 @@ class V8_EXPORT RegExp : public Object { */ class V8_EXPORT External : public Value { public: + static Local New(Isolate* isolate, void* value); + // Deprecated, do not use. static Local New(void* value); V8_INLINE static External* Cast(Value* obj); void* Value() const; diff --git a/samples/process.cc b/samples/process.cc index e6f2ee3..d1d36ca 100644 --- a/samples/process.cc +++ b/samples/process.cc @@ -324,7 +324,7 @@ Handle JsHttpRequestProcessor::WrapMap(map* obj) { // Wrap the raw C++ pointer in an External so it can be referenced // from within JavaScript. - Handle map_ptr = External::New(obj); + Handle map_ptr = External::New(GetIsolate(), obj); // Store the map pointer in the JavaScript wrapper. result->SetInternalField(0, map_ptr); @@ -432,7 +432,7 @@ Handle JsHttpRequestProcessor::WrapRequest(HttpRequest* request) { // Wrap the raw C++ pointer in an External so it can be referenced // from within JavaScript. - Handle request_ptr = External::New(request); + Handle request_ptr = External::New(GetIsolate(), request); // Store the request pointer in the JavaScript wrapper. result->SetInternalField(0, request_ptr); diff --git a/src/api.cc b/src/api.cc index 401007b..c1d3d1b 100644 --- a/src/api.cc +++ b/src/api.cc @@ -5369,17 +5369,22 @@ bool FunctionTemplate::HasInstance(v8::Handle value) { } -Local v8::External::New(void* value) { +Local v8::External::New(Isolate* isolate, void* value) { STATIC_ASSERT(sizeof(value) == sizeof(i::Address)); - i::Isolate* isolate = i::Isolate::Current(); - EnsureInitializedForIsolate(isolate, "v8::External::New()"); - LOG_API(isolate, "External::New"); - ENTER_V8(isolate); - i::Handle external = isolate->factory()->NewExternal(value); + i::Isolate* i_isolate = reinterpret_cast(isolate); + EnsureInitializedForIsolate(i_isolate, "v8::External::New()"); + LOG_API(i_isolate, "External::New"); + ENTER_V8(i_isolate); + i::Handle external = i_isolate->factory()->NewExternal(value); return Utils::ExternalToLocal(external); } +Local v8::External::New(void* value) { + return v8::External::New(Isolate::GetCurrent(), value); +} + + void* External::Value() const { return ExternalValue(*Utils::OpenHandle(this)); } diff --git a/test/cctest/test-accessors.cc b/test/cctest/test-accessors.cc index df4937e..4920ac2 100644 --- a/test/cctest/test-accessors.cc +++ b/test/cctest/test-accessors.cc @@ -122,18 +122,15 @@ THREADED_TEST(GlobalVariableAccess) { baz = 10; v8::HandleScope scope(CcTest::isolate()); v8::Handle templ = v8::FunctionTemplate::New(); - templ->InstanceTemplate()->SetAccessor(v8_str("foo"), - GetIntValue, - SetIntValue, - v8::External::New(&foo)); - templ->InstanceTemplate()->SetAccessor(v8_str("bar"), - GetIntValue, - SetIntValue, - v8::External::New(&bar)); - templ->InstanceTemplate()->SetAccessor(v8_str("baz"), - GetIntValue, - SetIntValue, - v8::External::New(&baz)); + templ->InstanceTemplate()->SetAccessor( + v8_str("foo"), GetIntValue, SetIntValue, + v8::External::New(CcTest::isolate(), &foo)); + templ->InstanceTemplate()->SetAccessor( + v8_str("bar"), GetIntValue, SetIntValue, + v8::External::New(CcTest::isolate(), &bar)); + templ->InstanceTemplate()->SetAccessor( + v8_str("baz"), GetIntValue, SetIntValue, + v8::External::New(CcTest::isolate(), &baz)); LocalContext env(0, templ->InstanceTemplate()); v8_compile("foo = (++bar) + baz")->Run(); CHECK_EQ(bar, -3); diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index f33d02b..55cdfe6 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -1306,7 +1306,8 @@ static void TestExternalPointerWrapping() { LocalContext env; v8::HandleScope scope(env->GetIsolate()); - v8::Handle data = v8::External::New(expected_ptr); + v8::Handle data = + v8::External::New(env->GetIsolate(), expected_ptr); v8::Handle obj = v8::Object::New(); obj->Set(v8_str("func"), @@ -3119,7 +3120,7 @@ THREADED_TEST(HiddenPropertiesWithInterceptors) { THREADED_TEST(External) { v8::HandleScope scope(CcTest::isolate()); int x = 3; - Local ext = v8::External::New(&x); + Local ext = v8::External::New(CcTest::isolate(), &x); LocalContext env; env->Global()->Set(v8_str("ext"), ext); Local reext_obj = Script::Compile(v8_str("this.ext"))->Run(); @@ -3131,10 +3132,10 @@ THREADED_TEST(External) { // Make sure unaligned pointers are wrapped properly. char* data = i::StrDup("0123456789"); - Local zero = v8::External::New(&data[0]); - Local one = v8::External::New(&data[1]); - Local two = v8::External::New(&data[2]); - Local three = v8::External::New(&data[3]); + Local zero = v8::External::New(CcTest::isolate(), &data[0]); + Local one = v8::External::New(CcTest::isolate(), &data[1]); + Local two = v8::External::New(CcTest::isolate(), &data[2]); + Local three = v8::External::New(CcTest::isolate(), &data[3]); char* char_ptr = reinterpret_cast(v8::External::Cast(*zero)->Value()); CHECK_EQ('0', *char_ptr); @@ -6874,7 +6875,7 @@ THREADED_TEST(WeakReference) { Whammy* whammy = new Whammy(CcTest::isolate()); templ->SetNamedPropertyHandler(WhammyPropertyGetter, 0, 0, 0, 0, - v8::External::New(whammy)); + v8::External::New(CcTest::isolate(), whammy)); const char* extension_list[] = { "v8/gc" }; v8::ExtensionConfiguration extensions(1, extension_list); v8::Handle context = @@ -11569,9 +11570,9 @@ THREADED_PROFILED_TEST(InterceptorCallICFastApi_TrivialSignature) { v8::Handle proto_templ = fun_templ->PrototypeTemplate(); proto_templ->Set(v8_str("method"), method_templ); v8::Handle templ = fun_templ->InstanceTemplate(); - templ->SetNamedPropertyHandler(InterceptorCallICFastApi, - NULL, NULL, NULL, NULL, - v8::External::New(&interceptor_call_count)); + templ->SetNamedPropertyHandler( + InterceptorCallICFastApi, NULL, NULL, NULL, NULL, + v8::External::New(CcTest::isolate(), &interceptor_call_count)); LocalContext context; v8::Handle fun = fun_templ->GetFunction(); GenerateSomeGarbage(); @@ -11598,9 +11599,9 @@ THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) { proto_templ->Set(v8_str("method"), method_templ); fun_templ->SetHiddenPrototype(true); v8::Handle templ = fun_templ->InstanceTemplate(); - templ->SetNamedPropertyHandler(InterceptorCallICFastApi, - NULL, NULL, NULL, NULL, - v8::External::New(&interceptor_call_count)); + templ->SetNamedPropertyHandler( + InterceptorCallICFastApi, NULL, NULL, NULL, NULL, + v8::External::New(CcTest::isolate(), &interceptor_call_count)); LocalContext context; v8::Handle fun = fun_templ->GetFunction(); GenerateSomeGarbage(); @@ -11630,9 +11631,9 @@ THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { proto_templ->Set(v8_str("method"), method_templ); fun_templ->SetHiddenPrototype(true); v8::Handle templ = fun_templ->InstanceTemplate(); - templ->SetNamedPropertyHandler(InterceptorCallICFastApi, - NULL, NULL, NULL, NULL, - v8::External::New(&interceptor_call_count)); + templ->SetNamedPropertyHandler( + InterceptorCallICFastApi, NULL, NULL, NULL, NULL, + v8::External::New(CcTest::isolate(), &interceptor_call_count)); LocalContext context; v8::Handle fun = fun_templ->GetFunction(); GenerateSomeGarbage(); @@ -11668,9 +11669,9 @@ THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { proto_templ->Set(v8_str("method"), method_templ); fun_templ->SetHiddenPrototype(true); v8::Handle templ = fun_templ->InstanceTemplate(); - templ->SetNamedPropertyHandler(InterceptorCallICFastApi, - NULL, NULL, NULL, NULL, - v8::External::New(&interceptor_call_count)); + templ->SetNamedPropertyHandler( + InterceptorCallICFastApi, NULL, NULL, NULL, NULL, + v8::External::New(CcTest::isolate(), &interceptor_call_count)); LocalContext context; v8::Handle fun = fun_templ->GetFunction(); GenerateSomeGarbage(); @@ -11706,9 +11707,9 @@ THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { proto_templ->Set(v8_str("method"), method_templ); fun_templ->SetHiddenPrototype(true); v8::Handle templ = fun_templ->InstanceTemplate(); - templ->SetNamedPropertyHandler(InterceptorCallICFastApi, - NULL, NULL, NULL, NULL, - v8::External::New(&interceptor_call_count)); + templ->SetNamedPropertyHandler( + InterceptorCallICFastApi, NULL, NULL, NULL, NULL, + v8::External::New(CcTest::isolate(), &interceptor_call_count)); LocalContext context; v8::Handle fun = fun_templ->GetFunction(); GenerateSomeGarbage(); @@ -11747,9 +11748,9 @@ THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { proto_templ->Set(v8_str("method"), method_templ); fun_templ->SetHiddenPrototype(true); v8::Handle templ = fun_templ->InstanceTemplate(); - templ->SetNamedPropertyHandler(InterceptorCallICFastApi, - NULL, NULL, NULL, NULL, - v8::External::New(&interceptor_call_count)); + templ->SetNamedPropertyHandler( + InterceptorCallICFastApi, NULL, NULL, NULL, NULL, + v8::External::New(CcTest::isolate(), &interceptor_call_count)); LocalContext context; v8::Handle fun = fun_templ->GetFunction(); GenerateSomeGarbage(); diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc index 9ef307c..33444ea 100644 --- a/test/cctest/test-cpu-profiler.cc +++ b/test/cctest/test-cpu-profiler.cc @@ -718,7 +718,8 @@ TEST(NativeAccessorUninitializedIC) { func_template->InstanceTemplate(); TestApiCallbacks accessors(100); - v8::Local data = v8::External::New(&accessors); + v8::Local data = + v8::External::New(env->GetIsolate(), &accessors); instance_template->SetAccessor( v8::String::New("foo"), &TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data); @@ -758,7 +759,8 @@ TEST(NativeAccessorMonomorphicIC) { func_template->InstanceTemplate(); TestApiCallbacks accessors(1); - v8::Local data = v8::External::New(&accessors); + v8::Local data = + v8::External::New(env->GetIsolate(), &accessors); instance_template->SetAccessor( v8::String::New("foo"), &TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data); @@ -807,7 +809,8 @@ TEST(NativeMethodUninitializedIC) { v8::HandleScope scope(env->GetIsolate()); TestApiCallbacks callbacks(100); - v8::Local data = v8::External::New(&callbacks); + v8::Local data = + v8::External::New(env->GetIsolate(), &callbacks); v8::Local func_template = v8::FunctionTemplate::New(); func_template->SetClassName(v8::String::New("Test_InstanceCostructor")); @@ -844,7 +847,8 @@ TEST(NativeMethodMonomorphicIC) { v8::HandleScope scope(env->GetIsolate()); TestApiCallbacks callbacks(1); - v8::Local data = v8::External::New(&callbacks); + v8::Local data = + v8::External::New(env->GetIsolate(), &callbacks); v8::Local func_template = v8::FunctionTemplate::New(); func_template->SetClassName(v8::String::New("Test_InstanceCostructor")); diff --git a/test/cctest/test-decls.cc b/test/cctest/test-decls.cc index de27286..1d09f9c 100644 --- a/test/cctest/test-decls.cc +++ b/test/cctest/test-decls.cc @@ -119,7 +119,7 @@ void DeclarationContext::InitializeIfNeeded() { Isolate* isolate = CcTest::isolate(); HandleScope scope(isolate); Local function = FunctionTemplate::New(); - Local data = External::New(this); + Local data = External::New(CcTest::isolate(), this); GetHolder(function)->SetNamedPropertyHandler(&HandleGet, &HandleSet, &HandleQuery, -- 2.7.4