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

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

Issue 1395583004: Revert of Don't compile functions in a context the caller doesn't have access to (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 months 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 | « src/v8natives.js ('k') | test/mjsunit/cross-realm-filtering.js » ('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 8723 matching lines...) Expand 10 before | Expand all | Expand 10 after
8734 } 8734 }
8735 8735
8736 8736
8737 static bool AccessAlwaysBlocked(Local<v8::Object> global, Local<Value> name, 8737 static bool AccessAlwaysBlocked(Local<v8::Object> global, Local<Value> name,
8738 v8::AccessType type, Local<Value> data) { 8738 v8::AccessType type, Local<Value> data) {
8739 i::PrintF("Access blocked.\n"); 8739 i::PrintF("Access blocked.\n");
8740 return false; 8740 return false;
8741 } 8741 }
8742 8742
8743 8743
8744 static bool AccessAlwaysAllowed(Local<v8::Object> global, Local<Value> name,
8745 v8::AccessType type, Local<Value> data) {
8746 i::PrintF("Access allowed.\n");
8747 return true;
8748 }
8749
8750
8751 THREADED_TEST(AccessControlGetOwnPropertyNames) { 8744 THREADED_TEST(AccessControlGetOwnPropertyNames) {
8752 v8::Isolate* isolate = CcTest::isolate(); 8745 v8::Isolate* isolate = CcTest::isolate();
8753 v8::HandleScope handle_scope(isolate); 8746 v8::HandleScope handle_scope(isolate);
8754 v8::Handle<v8::ObjectTemplate> obj_template = 8747 v8::Handle<v8::ObjectTemplate> obj_template =
8755 v8::ObjectTemplate::New(isolate); 8748 v8::ObjectTemplate::New(isolate);
8756 8749
8757 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); 8750 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42));
8758 obj_template->SetAccessCheckCallbacks(AccessAlwaysBlocked, NULL); 8751 obj_template->SetAccessCheckCallbacks(AccessAlwaysBlocked, NULL);
8759 8752
8760 // Add an accessor accessible by cross-domain JS code. 8753 // Add an accessor accessible by cross-domain JS code.
(...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after
9980 // Put the function into context1 and call it before and after 9973 // Put the function into context1 and call it before and after
9981 // detaching the global. Before detaching, the call succeeds and 9974 // detaching the global. Before detaching, the call succeeds and
9982 // after detaching and exception is thrown. 9975 // after detaching and exception is thrown.
9983 context1->Enter(); 9976 context1->Enter();
9984 context1->Global()->Set(v8_str("fun"), fun); 9977 context1->Global()->Set(v8_str("fun"), fun);
9985 v8::Handle<v8::Value> x_value = CompileRun("fun('x')"); 9978 v8::Handle<v8::Value> x_value = CompileRun("fun('x')");
9986 CHECK_EQ(42, x_value->Int32Value()); 9979 CHECK_EQ(42, x_value->Int32Value());
9987 context0->DetachGlobal(); 9980 context0->DetachGlobal();
9988 v8::TryCatch catcher(isolate); 9981 v8::TryCatch catcher(isolate);
9989 x_value = CompileRun("fun('x')"); 9982 x_value = CompileRun("fun('x')");
9990 CHECK(x_value->IsUndefined()); 9983 CHECK_EQ(42, x_value->Int32Value());
9991 context1->Exit(); 9984 context1->Exit();
9992 } 9985 }
9993 9986
9994 9987
9995 THREADED_TEST(CrossLazyLoad) { 9988 THREADED_TEST(CrossLazyLoad) {
9996 v8::HandleScope scope(CcTest::isolate()); 9989 v8::HandleScope scope(CcTest::isolate());
9997 LocalContext other; 9990 LocalContext other;
9998 LocalContext current; 9991 LocalContext current;
9999 9992
10000 Local<String> token = v8_str("<security token>"); 9993 Local<String> token = v8_str("<security token>");
(...skipping 11945 matching lines...) Expand 10 before | Expand all | Expand 10 after
21946 LocalContext env; 21939 LocalContext env;
21947 21940
21948 env->Global()->Set(v8_str("keys"), v8::Array::GetKeysIterator(isolate)); 21941 env->Global()->Set(v8_str("keys"), v8::Array::GetKeysIterator(isolate));
21949 env->Global()->Set(v8_str("values"), v8::Array::GetValuesIterator(isolate)); 21942 env->Global()->Set(v8_str("values"), v8::Array::GetValuesIterator(isolate));
21950 env->Global()->Set(v8_str("entries"), v8::Array::GetEntriesIterator(isolate)); 21943 env->Global()->Set(v8_str("entries"), v8::Array::GetEntriesIterator(isolate));
21951 21944
21952 ExpectString("typeof keys", "function"); 21945 ExpectString("typeof keys", "function");
21953 ExpectString("typeof values", "function"); 21946 ExpectString("typeof values", "function");
21954 ExpectString("typeof entries", "function"); 21947 ExpectString("typeof entries", "function");
21955 } 21948 }
21956
21957
21958 Local<v8::Context> call_eval_context;
21959 Local<v8::Function> call_eval_bound_function;
21960 static void CallEval(const v8::FunctionCallbackInfo<v8::Value>& args) {
21961 v8::Context::Scope scope(call_eval_context);
21962 args.GetReturnValue().Set(
21963 call_eval_bound_function->Call(call_eval_context->Global(), 0, NULL));
21964 }
21965
21966
21967 TEST(CrossActivationEval) {
21968 LocalContext env;
21969 v8::Isolate* isolate = env->GetIsolate();
21970 v8::HandleScope scope(isolate);
21971 {
21972 call_eval_context = v8::Context::New(isolate);
21973 v8::Context::Scope scope(call_eval_context);
21974 call_eval_bound_function =
21975 Local<Function>::Cast(CompileRun("eval.bind(this, '1')"));
21976 }
21977 env->Global()->Set(
21978 v8_str("CallEval"),
21979 v8::FunctionTemplate::New(isolate, CallEval)->GetFunction());
21980 Local<Value> result = CompileRun("CallEval();");
21981 CHECK(result->IsInt32());
21982 CHECK_EQ(1, result->Int32Value());
21983 }
21984
21985
21986 TEST(EvalInAccessCheckedContext) {
21987 v8::Isolate* isolate = CcTest::isolate();
21988 v8::HandleScope scope(isolate);
21989
21990 v8::Handle<v8::ObjectTemplate> obj_template =
21991 v8::ObjectTemplate::New(isolate);
21992
21993 obj_template->SetAccessCheckCallbacks(AccessAlwaysAllowed, NULL);
21994
21995 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
21996 v8::Local<Context> context1 = Context::New(isolate, NULL, obj_template);
21997
21998 Local<Value> foo = v8_str("foo");
21999 Local<Value> bar = v8_str("bar");
22000
22001 // Set to different domains.
22002 context0->SetSecurityToken(foo);
22003 context1->SetSecurityToken(bar);
22004
22005 // Set up function in context0 that uses eval from context0.
22006 context0->Enter();
22007 v8::Handle<v8::Value> fun = CompileRun(
22008 "var x = 42;"
22009 "(function() {"
22010 " var e = eval;"
22011 " return function(s) { return e(s); }"
22012 "})()");
22013 context0->Exit();
22014
22015 // Put the function into context1 and call it. Since the access check
22016 // callback always returns true, the call succeeds even though the tokens
22017 // are different.
22018 context1->Enter();
22019 context1->Global()->Set(v8_str("fun"), fun);
22020 v8::Handle<v8::Value> x_value = CompileRun("fun('x')");
22021 CHECK_EQ(42, x_value->Int32Value());
22022 context1->Exit();
22023 }
OLDNEW
« no previous file with comments | « src/v8natives.js ('k') | test/mjsunit/cross-realm-filtering.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698