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

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

Issue 2034083002: 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: updates Created 4 years, 6 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
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 10143 matching lines...) Expand 10 before | Expand all | Expand 10 after
10154 CHECK_EQ(42, g_echo_value); // Make sure we didn't call the setter. 10154 CHECK_EQ(42, g_echo_value); // Make sure we didn't call the setter.
10155 } 10155 }
10156 10156
10157 static bool AccessAlwaysBlocked(Local<v8::Context> accessing_context, 10157 static bool AccessAlwaysBlocked(Local<v8::Context> accessing_context,
10158 Local<v8::Object> global, 10158 Local<v8::Object> global,
10159 Local<v8::Value> data) { 10159 Local<v8::Value> data) {
10160 i::PrintF("Access blocked.\n"); 10160 i::PrintF("Access blocked.\n");
10161 return false; 10161 return false;
10162 } 10162 }
10163 10163
10164 static bool AccessAlwaysAllowed(Local<v8::Context> accessing_context,
10165 Local<v8::Object> global,
10166 Local<v8::Value> data) {
10167 i::PrintF("Access allowed.\n");
10168 return true;
10169 }
10164 10170
10165 THREADED_TEST(AccessControlGetOwnPropertyNames) { 10171 THREADED_TEST(AccessControlGetOwnPropertyNames) {
10166 v8::Isolate* isolate = CcTest::isolate(); 10172 v8::Isolate* isolate = CcTest::isolate();
10167 v8::HandleScope handle_scope(isolate); 10173 v8::HandleScope handle_scope(isolate);
10168 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate); 10174 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate);
10169 10175
10170 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); 10176 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42));
10171 obj_template->SetAccessCheckCallback(AccessAlwaysBlocked); 10177 obj_template->SetAccessCheckCallback(AccessAlwaysBlocked);
10172 10178
10173 // Add an accessor accessible by cross-domain JS code. 10179 // Add an accessor accessible by cross-domain JS code.
(...skipping 15178 matching lines...) Expand 10 before | Expand all | Expand 10 after
25352 } 25358 }
25353 25359
25354 TEST(PrivateForApiIsNumber) { 25360 TEST(PrivateForApiIsNumber) {
25355 LocalContext context; 25361 LocalContext context;
25356 v8::Isolate* isolate = CcTest::isolate(); 25362 v8::Isolate* isolate = CcTest::isolate();
25357 v8::HandleScope scope(isolate); 25363 v8::HandleScope scope(isolate);
25358 25364
25359 // Shouldn't crash. 25365 // Shouldn't crash.
25360 v8::Private::ForApi(isolate, v8_str("42")); 25366 v8::Private::ForApi(isolate, v8_str("42"));
25361 } 25367 }
25368
25369 Local<v8::Context> call_eval_context;
25370 Local<v8::Function> call_eval_bound_function;
25371
25372 static void CallEval(const v8::FunctionCallbackInfo<v8::Value>& args) {
25373 v8::Context::Scope scope(call_eval_context);
25374 args.GetReturnValue().Set(
25375 call_eval_bound_function
25376 ->Call(call_eval_context, call_eval_context->Global(), 0, NULL)
25377 .ToLocalChecked());
25378 }
25379
25380 TEST(CrossActivationEval) {
25381 LocalContext env;
25382 v8::Isolate* isolate = env->GetIsolate();
25383 v8::HandleScope scope(isolate);
25384 {
25385 call_eval_context = v8::Context::New(isolate);
25386 v8::Context::Scope scope(call_eval_context);
25387 call_eval_bound_function =
25388 Local<Function>::Cast(CompileRun("eval.bind(this, '1')"));
25389 }
25390 env->Global()
25391 ->Set(env.local(), v8_str("CallEval"),
25392 v8::FunctionTemplate::New(isolate, CallEval)
25393 ->GetFunction(env.local())
25394 .ToLocalChecked())
25395 .FromJust();
25396 Local<Value> result = CompileRun("CallEval();");
25397 CHECK(result->IsInt32());
25398 CHECK_EQ(1, result->Int32Value(env.local()).FromJust());
25399 }
25400
25401 TEST(EvalInAccessCheckedContext) {
25402 v8::Isolate* isolate = CcTest::isolate();
25403 v8::HandleScope scope(isolate);
25404
25405 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate);
25406
25407 obj_template->SetAccessCheckCallback(AccessAlwaysAllowed);
25408
25409 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
25410 v8::Local<Context> context1 = Context::New(isolate, NULL, obj_template);
25411
25412 Local<Value> foo = v8_str("foo");
25413 Local<Value> bar = v8_str("bar");
25414
25415 // Set to different domains.
25416 context0->SetSecurityToken(foo);
25417 context1->SetSecurityToken(bar);
25418
25419 // Set up function in context0 that uses eval from context0.
25420 context0->Enter();
25421 v8::Local<v8::Value> fun = CompileRun(
25422 "var x = 42;"
25423 "(function() {"
25424 " var e = eval;"
25425 " return function(s) { return e(s); }"
25426 "})()");
25427 context0->Exit();
25428
25429 // Put the function into context1 and call it. Since the access check
25430 // callback always returns true, the call succeeds even though the tokens
25431 // are different.
25432 context1->Enter();
25433 context1->Global()->Set(context1, v8_str("fun"), fun).FromJust();
25434 v8::Local<v8::Value> x_value = CompileRun("fun('x')");
25435 CHECK_EQ(42, x_value->Int32Value(context1).FromJust());
25436 context1->Exit();
25437 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698