Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: test/cctest/test-api.cc

Issue 1431473003: Mark GetCallingContext as soon-to-be deprecated (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 13541 matching lines...) Expand 10 before | Expand all | Expand 10 after
13552 { 13552 {
13553 v8::TryCatch try_catch(isolate); 13553 v8::TryCatch try_catch(isolate);
13554 CHECK(access_checked->DefineOwnProperty(env.local(), v8_str("foo"), 13554 CHECK(access_checked->DefineOwnProperty(env.local(), v8_str("foo"),
13555 v8::Integer::New(isolate, 42)) 13555 v8::Integer::New(isolate, 42))
13556 .IsNothing()); 13556 .IsNothing());
13557 CHECK(try_catch.HasCaught()); 13557 CHECK(try_catch.HasCaught());
13558 } 13558 }
13559 } 13559 }
13560 13560
13561 13561
13562 static v8::Local<Context> calling_context0;
13563 static v8::Local<Context> calling_context1;
13564 static v8::Local<Context> calling_context2;
13565
13566
13567 // Check that the call to the callback is initiated in
13568 // calling_context2, the directly calling context is calling_context1
13569 // and the callback itself is in calling_context0.
13570 static void GetCallingContextCallback(
13571 const v8::FunctionCallbackInfo<v8::Value>& args) {
13572 ApiTestFuzzer::Fuzz();
13573 CHECK(args.GetIsolate()->GetCurrentContext() == calling_context0);
13574 CHECK(args.GetIsolate()->GetCallingContext() == calling_context1);
13575 CHECK(args.GetIsolate()->GetEnteredContext() == calling_context2);
13576 args.GetReturnValue().Set(42);
13577 }
13578
13579
13580 THREADED_TEST(GetCurrentContextWhenNotInContext) { 13562 THREADED_TEST(GetCurrentContextWhenNotInContext) {
13581 i::Isolate* isolate = CcTest::i_isolate(); 13563 i::Isolate* isolate = CcTest::i_isolate();
13582 CHECK(isolate != NULL); 13564 CHECK(isolate != NULL);
13583 CHECK(isolate->context() == NULL); 13565 CHECK(isolate->context() == NULL);
13584 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); 13566 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
13585 v8::HandleScope scope(v8_isolate); 13567 v8::HandleScope scope(v8_isolate);
13586 // The following should not crash, but return an empty handle. 13568 // The following should not crash, but return an empty handle.
13587 v8::Local<v8::Context> current = v8_isolate->GetCurrentContext(); 13569 v8::Local<v8::Context> current = v8_isolate->GetCurrentContext();
13588 CHECK(current.IsEmpty()); 13570 CHECK(current.IsEmpty());
13589 } 13571 }
13590 13572
13591 13573
13592 THREADED_TEST(GetCallingContext) {
13593 v8::Isolate* isolate = CcTest::isolate();
13594 v8::HandleScope scope(isolate);
13595
13596 Local<Context> calling_context0(Context::New(isolate));
13597 Local<Context> calling_context1(Context::New(isolate));
13598 Local<Context> calling_context2(Context::New(isolate));
13599 ::calling_context0 = calling_context0;
13600 ::calling_context1 = calling_context1;
13601 ::calling_context2 = calling_context2;
13602
13603 // Allow cross-domain access.
13604 Local<String> token = v8_str("<security token>");
13605 calling_context0->SetSecurityToken(token);
13606 calling_context1->SetSecurityToken(token);
13607 calling_context2->SetSecurityToken(token);
13608
13609 // Create an object with a C++ callback in context0.
13610 calling_context0->Enter();
13611 Local<v8::FunctionTemplate> callback_templ =
13612 v8::FunctionTemplate::New(isolate, GetCallingContextCallback);
13613 calling_context0->Global()->Set(v8_str("callback"),
13614 callback_templ->GetFunction());
13615 calling_context0->Exit();
13616
13617 // Expose context0 in context1 and set up a function that calls the
13618 // callback function.
13619 calling_context1->Enter();
13620 calling_context1->Global()->Set(v8_str("context0"),
13621 calling_context0->Global());
13622 CompileRun("function f() { context0.callback() }");
13623 calling_context1->Exit();
13624
13625 // Expose context1 in context2 and call the callback function in
13626 // context0 indirectly through f in context1.
13627 calling_context2->Enter();
13628 calling_context2->Global()->Set(v8_str("context1"),
13629 calling_context1->Global());
13630 CompileRun("context1.f()");
13631 calling_context2->Exit();
13632 ::calling_context0.Clear();
13633 ::calling_context1.Clear();
13634 ::calling_context2.Clear();
13635 }
13636
13637
13638 // Check that a variable declaration with no explicit initialization 13574 // Check that a variable declaration with no explicit initialization
13639 // value does shadow an existing property in the prototype chain. 13575 // value does shadow an existing property in the prototype chain.
13640 THREADED_TEST(InitGlobalVarInProtoChain) { 13576 THREADED_TEST(InitGlobalVarInProtoChain) {
13641 LocalContext context; 13577 LocalContext context;
13642 v8::HandleScope scope(context->GetIsolate()); 13578 v8::HandleScope scope(context->GetIsolate());
13643 // Introduce a variable in the prototype chain. 13579 // Introduce a variable in the prototype chain.
13644 CompileRun("__proto__.x = 42"); 13580 CompileRun("__proto__.x = 42");
13645 v8::Handle<v8::Value> result = CompileRun("var x = 43; x"); 13581 v8::Handle<v8::Value> result = CompileRun("var x = 43; x");
13646 CHECK(!result->IsUndefined()); 13582 CHECK(!result->IsUndefined());
13647 CHECK_EQ(43, result->Int32Value()); 13583 CHECK_EQ(43, result->Int32Value());
(...skipping 8308 matching lines...) Expand 10 before | Expand all | Expand 10 after
21956 env2->Global()->Set(v8_str("obj2"), object2); 21892 env2->Global()->Set(v8_str("obj2"), object2);
21957 ExpectString("typeof obj2.values", "function"); 21893 ExpectString("typeof obj2.values", "function");
21958 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values"))); 21894 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values")));
21959 21895
21960 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values"))); 21896 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values")));
21961 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2)); 21897 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2));
21962 auto ctx2 = v8::Utils::OpenHandle(*env2.local()); 21898 auto ctx2 = v8::Utils::OpenHandle(*env2.local());
21963 CHECK_EQ(fn2->GetCreationContext(), *ctx2); 21899 CHECK_EQ(fn2->GetCreationContext(), *ctx2);
21964 } 21900 }
21965 } 21901 }
OLDNEW
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698