diff options
Diffstat (limited to 'deps/v8/test/cctest/test-decls.cc')
-rw-r--r-- | deps/v8/test/cctest/test-decls.cc | 102 |
1 files changed, 57 insertions, 45 deletions
diff --git a/deps/v8/test/cctest/test-decls.cc b/deps/v8/test/cctest/test-decls.cc index de27286dac..1f22c9ff3a 100644 --- a/deps/v8/test/cctest/test-decls.cc +++ b/deps/v8/test/cctest/test-decls.cc @@ -56,7 +56,7 @@ class DeclarationContext { HandleScope scope(isolate); Local<Context> context = Local<Context>::New(isolate, context_); context->Exit(); - context_.Dispose(); + context_.Reset(); } } @@ -96,6 +96,8 @@ class DeclarationContext { static void HandleQuery(Local<String> key, const v8::PropertyCallbackInfo<v8::Integer>& info); + v8::Isolate* isolate() const { return CcTest::isolate(); } + private: bool is_initialized_; Persistent<Context> context_; @@ -118,8 +120,8 @@ void DeclarationContext::InitializeIfNeeded() { if (is_initialized_) return; Isolate* isolate = CcTest::isolate(); HandleScope scope(isolate); - Local<FunctionTemplate> function = FunctionTemplate::New(); - Local<Value> data = External::New(this); + Local<FunctionTemplate> function = FunctionTemplate::New(isolate); + Local<Value> data = External::New(CcTest::isolate(), this); GetHolder(function)->SetNamedPropertyHandler(&HandleGet, &HandleSet, &HandleQuery, @@ -147,7 +149,8 @@ void DeclarationContext::Check(const char* source, HandleScope scope(CcTest::isolate()); TryCatch catcher; catcher.SetVerbose(true); - Local<Script> script = Script::Compile(String::New(source)); + Local<Script> script = + Script::Compile(String::NewFromUtf8(CcTest::isolate(), source)); if (expectations == EXPECT_ERROR) { CHECK(script.IsEmpty()); return; @@ -243,7 +246,7 @@ TEST(Unknown) { 1, // access 2, // declaration + initialization 2, // declaration + initialization - EXPECT_RESULT, Number::New(0)); + EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); } { DeclarationContext context; @@ -277,7 +280,7 @@ TEST(Unknown) { class PresentPropertyContext: public DeclarationContext { protected: virtual v8::Handle<Integer> Query(Local<String> key) { - return Integer::New(v8::None); + return Integer::New(isolate(), v8::None); } }; @@ -299,7 +302,7 @@ TEST(Present) { 1, // access 1, // initialization 2, // declaration + initialization - EXPECT_RESULT, Number::New(0)); + EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); } { PresentPropertyContext context; @@ -323,7 +326,7 @@ TEST(Present) { 1, // access 1, // initialization 1, // (re-)declaration - EXPECT_RESULT, Number::New(0)); + EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); } } @@ -355,7 +358,7 @@ TEST(Absent) { 1, // access 2, // declaration + initialization 2, // declaration + initialization - EXPECT_RESULT, Number::New(0)); + EXPECT_RESULT, Number::New(isolate, 0)); } { AbsentPropertyContext context; @@ -415,7 +418,7 @@ class AppearingPropertyContext: public DeclarationContext { // Return that the property is present so we only get the // setter called when initializing with a value. state_ = UNKNOWN; - return Integer::New(v8::None); + return Integer::New(isolate(), v8::None); default: CHECK(state_ == UNKNOWN); break; @@ -446,7 +449,7 @@ TEST(Appearing) { 1, // access 2, // declaration + initialization 2, // declaration + initialization - EXPECT_RESULT, Number::New(0)); + EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); } { AppearingPropertyContext context; @@ -501,7 +504,7 @@ class ReappearingPropertyContext: public DeclarationContext { // Ignore the second declaration by returning // that the property is already there. state_ = INITIALIZE; - return Integer::New(v8::None); + return Integer::New(isolate(), v8::None); case INITIALIZE: // Force an initialization by returning that // the property is absent. This will make sure @@ -538,10 +541,12 @@ TEST(Reappearing) { class ExistsInPrototypeContext: public DeclarationContext { + public: + ExistsInPrototypeContext() { InitializeIfNeeded(); } protected: virtual v8::Handle<Integer> Query(Local<String> key) { // Let it seem that the property exists in the prototype object. - return Integer::New(v8::None); + return Integer::New(isolate(), v8::None); } // Use the prototype as the holder for the interceptors. @@ -562,7 +567,7 @@ TEST(ExistsInPrototype) { 0, 0, 0, - EXPECT_RESULT, Number::New(87)); + EXPECT_RESULT, Number::New(CcTest::isolate(), 87)); } { ExistsInPrototypeContext context; @@ -578,7 +583,7 @@ TEST(ExistsInPrototype) { 0, 0, 0, - EXPECT_RESULT, Number::New(0)); + EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); } { ExistsInPrototypeContext context; @@ -594,7 +599,7 @@ TEST(ExistsInPrototype) { 0, 0, 0, - EXPECT_RESULT, Number::New(0)); + EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); } } @@ -633,23 +638,23 @@ TEST(AbsentInPrototype) { class ExistsInHiddenPrototypeContext: public DeclarationContext { public: ExistsInHiddenPrototypeContext() { - hidden_proto_ = FunctionTemplate::New(); + hidden_proto_ = FunctionTemplate::New(CcTest::isolate()); hidden_proto_->SetHiddenPrototype(true); } protected: virtual v8::Handle<Integer> Query(Local<String> key) { // Let it seem that the property exists in the hidden prototype object. - return Integer::New(v8::None); + return Integer::New(isolate(), v8::None); } // Install the hidden prototype after the global object has been created. virtual void PostInitializeContext(Handle<Context> context) { Local<Object> global_object = context->Global(); Local<Object> hidden_proto = hidden_proto_->GetFunction()->NewInstance(); - context->DetachGlobal(); - context->Global()->SetPrototype(hidden_proto); - context->ReattachGlobal(global_object); + Local<Object> inner_global = + Local<Object>::Cast(global_object->GetPrototype()); + inner_global->SetPrototype(hidden_proto); } // Use the hidden prototype as the holder for the interceptors. @@ -679,7 +684,7 @@ TEST(ExistsInHiddenPrototype) { 1, // access 1, // initialization 2, // declaration + initialization - EXPECT_RESULT, Number::New(0)); + EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); } { ExistsInHiddenPrototypeContext context; @@ -705,7 +710,7 @@ TEST(ExistsInHiddenPrototype) { 0, 0, 1, // (re-)declaration - EXPECT_RESULT, Number::New(0)); + EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); } } @@ -729,7 +734,8 @@ class SimpleContext { HandleScope scope(context_->GetIsolate()); TryCatch catcher; catcher.SetVerbose(true); - Local<Script> script = Script::Compile(String::New(source)); + Local<Script> script = + Script::Compile(String::NewFromUtf8(context_->GetIsolate(), source)); if (expectations == EXPECT_ERROR) { CHECK(script.IsEmpty()); return; @@ -757,40 +763,41 @@ class SimpleContext { TEST(CrossScriptReferences) { - HandleScope scope(CcTest::isolate()); + v8::Isolate* isolate = CcTest::isolate(); + HandleScope scope(isolate); { SimpleContext context; context.Check("var x = 1; x", - EXPECT_RESULT, Number::New(1)); + EXPECT_RESULT, Number::New(isolate, 1)); context.Check("var x = 2; x", - EXPECT_RESULT, Number::New(2)); + EXPECT_RESULT, Number::New(isolate, 2)); context.Check("const x = 3; x", - EXPECT_RESULT, Number::New(3)); + EXPECT_RESULT, Number::New(isolate, 3)); context.Check("const x = 4; x", - EXPECT_RESULT, Number::New(4)); + EXPECT_RESULT, Number::New(isolate, 4)); context.Check("x = 5; x", - EXPECT_RESULT, Number::New(5)); + EXPECT_RESULT, Number::New(isolate, 5)); context.Check("var x = 6; x", - EXPECT_RESULT, Number::New(6)); + EXPECT_RESULT, Number::New(isolate, 6)); context.Check("this.x", - EXPECT_RESULT, Number::New(6)); + EXPECT_RESULT, Number::New(isolate, 6)); context.Check("function x() { return 7 }; x()", - EXPECT_RESULT, Number::New(7)); + EXPECT_RESULT, Number::New(isolate, 7)); } { SimpleContext context; context.Check("const x = 1; x", - EXPECT_RESULT, Number::New(1)); + EXPECT_RESULT, Number::New(isolate, 1)); context.Check("var x = 2; x", // assignment ignored - EXPECT_RESULT, Number::New(1)); + EXPECT_RESULT, Number::New(isolate, 1)); context.Check("const x = 3; x", - EXPECT_RESULT, Number::New(1)); + EXPECT_RESULT, Number::New(isolate, 1)); context.Check("x = 4; x", // assignment ignored - EXPECT_RESULT, Number::New(1)); + EXPECT_RESULT, Number::New(isolate, 1)); context.Check("var x = 5; x", // assignment ignored - EXPECT_RESULT, Number::New(1)); + EXPECT_RESULT, Number::New(isolate, 1)); context.Check("this.x", - EXPECT_RESULT, Number::New(1)); + EXPECT_RESULT, Number::New(isolate, 1)); context.Check("function x() { return 7 }; x", EXPECT_EXCEPTION); } @@ -802,7 +809,8 @@ TEST(CrossScriptReferencesHarmony) { i::FLAG_harmony_scoping = true; i::FLAG_harmony_modules = true; - HandleScope scope(CcTest::isolate()); + v8::Isolate* isolate = CcTest::isolate(); + HandleScope scope(isolate); const char* decs[] = { "var x = 1; x", "x", "this.x", @@ -815,12 +823,14 @@ TEST(CrossScriptReferencesHarmony) { for (int i = 0; decs[i] != NULL; i += 3) { SimpleContext context; - context.Check(decs[i], EXPECT_RESULT, Number::New(1)); - context.Check(decs[i+1], EXPECT_RESULT, Number::New(1)); + context.Check(decs[i], EXPECT_RESULT, Number::New(isolate, 1)); + context.Check(decs[i+1], EXPECT_RESULT, Number::New(isolate, 1)); // TODO(rossberg): The current ES6 draft spec does not reflect lexical // bindings on the global object. However, this will probably change, in // which case we reactivate the following test. - if (i/3 < 2) context.Check(decs[i+2], EXPECT_RESULT, Number::New(1)); + if (i/3 < 2) { + context.Check(decs[i+2], EXPECT_RESULT, Number::New(isolate, 1)); + } } } @@ -852,12 +862,14 @@ TEST(CrossScriptConflicts) { for (int i = 0; firsts[i] != NULL; ++i) { for (int j = 0; seconds[j] != NULL; ++j) { SimpleContext context; - context.Check(firsts[i], EXPECT_RESULT, Number::New(1)); + context.Check(firsts[i], EXPECT_RESULT, + Number::New(CcTest::isolate(), 1)); // TODO(rossberg): All tests should actually be errors in Harmony, // but we currently do not detect the cases where the first declaration // is not lexical. context.Check(seconds[j], - i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2)); + i < 2 ? EXPECT_RESULT : EXPECT_ERROR, + Number::New(CcTest::isolate(), 2)); } } } |