OLD | NEW |
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 8506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8517 Local<v8::Object> global2 = env2->Global(); | 8517 Local<v8::Object> global2 = env2->Global(); |
8518 global2->Set(v8_str("prop"), v8::Integer::New(1)); | 8518 global2->Set(v8_str("prop"), v8::Integer::New(1)); |
8519 CompileRun("function getProp() {return prop;}"); | 8519 CompileRun("function getProp() {return prop;}"); |
8520 | 8520 |
8521 env1->Global()->Set(v8_str("getProp"), | 8521 env1->Global()->Set(v8_str("getProp"), |
8522 global2->Get(v8_str("getProp"))); | 8522 global2->Get(v8_str("getProp"))); |
8523 | 8523 |
8524 // Detach env2's global, and reuse the global object of env2 | 8524 // Detach env2's global, and reuse the global object of env2 |
8525 env2->Exit(); | 8525 env2->Exit(); |
8526 env2->DetachGlobal(); | 8526 env2->DetachGlobal(); |
8527 // env2 has a new global object. | |
8528 CHECK(!env2->Global()->Equals(global2)); | |
8529 | 8527 |
8530 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), | 8528 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), |
8531 0, | 8529 0, |
8532 v8::Handle<v8::ObjectTemplate>(), | 8530 v8::Handle<v8::ObjectTemplate>(), |
8533 global2); | 8531 global2); |
8534 env3->SetSecurityToken(v8_str("bar")); | 8532 env3->SetSecurityToken(v8_str("bar")); |
8535 env3->Enter(); | 8533 env3->Enter(); |
8536 | 8534 |
8537 Local<v8::Object> global3 = env3->Global(); | 8535 Local<v8::Object> global3 = env3->Global(); |
8538 CHECK_EQ(global2, global3); | 8536 CHECK_EQ(global2, global3); |
(...skipping 14 matching lines...) Expand all Loading... |
8553 } | 8551 } |
8554 | 8552 |
8555 // Check that env3 is not accessible from env1 | 8553 // Check that env3 is not accessible from env1 |
8556 { | 8554 { |
8557 Local<Value> r = global3->Get(v8_str("prop2")); | 8555 Local<Value> r = global3->Get(v8_str("prop2")); |
8558 CHECK(r->IsUndefined()); | 8556 CHECK(r->IsUndefined()); |
8559 } | 8557 } |
8560 } | 8558 } |
8561 | 8559 |
8562 | 8560 |
8563 TEST(DetachAndReattachGlobal) { | 8561 TEST(DetachGlobal) { |
8564 LocalContext env1; | 8562 LocalContext env1; |
8565 v8::HandleScope scope(env1->GetIsolate()); | 8563 v8::HandleScope scope(env1->GetIsolate()); |
8566 | 8564 |
8567 // Create second environment. | 8565 // Create second environment. |
8568 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); | 8566 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
8569 | 8567 |
8570 Local<Value> foo = v8_str("foo"); | 8568 Local<Value> foo = v8_str("foo"); |
8571 | 8569 |
8572 // Set same security token for env1 and env2. | 8570 // Set same security token for env1 and env2. |
8573 env1->SetSecurityToken(foo); | 8571 env1->SetSecurityToken(foo); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8618 CHECK_EQ(24, result->Int32Value()); | 8616 CHECK_EQ(24, result->Int32Value()); |
8619 | 8617 |
8620 // Change security token for env3 to something different from env1 and env2. | 8618 // Change security token for env3 to something different from env1 and env2. |
8621 env3->SetSecurityToken(v8_str("bar")); | 8619 env3->SetSecurityToken(v8_str("bar")); |
8622 | 8620 |
8623 // Check that we do not have access to other.p in env1. |other| is now | 8621 // Check that we do not have access to other.p in env1. |other| is now |
8624 // the global object for env3 which has a different security token, | 8622 // the global object for env3 which has a different security token, |
8625 // so access should be blocked. | 8623 // so access should be blocked. |
8626 result = CompileRun("other.p"); | 8624 result = CompileRun("other.p"); |
8627 CHECK(result->IsUndefined()); | 8625 CHECK(result->IsUndefined()); |
8628 | |
8629 // Detach the global for env3 and reattach it to env2. | |
8630 env3->DetachGlobal(); | |
8631 env2->ReattachGlobal(global2); | |
8632 | |
8633 // Check that we have access to other.p again in env1. |other| is now | |
8634 // the global object for env2 which has the same security token as env1. | |
8635 result = CompileRun("other.p"); | |
8636 CHECK(result->IsInt32()); | |
8637 CHECK_EQ(42, result->Int32Value()); | |
8638 } | 8626 } |
8639 | 8627 |
8640 | 8628 |
8641 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; | 8629 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; |
8642 static bool NamedAccessBlocker(Local<v8::Object> global, | 8630 static bool NamedAccessBlocker(Local<v8::Object> global, |
8643 Local<Value> name, | 8631 Local<Value> name, |
8644 v8::AccessType type, | 8632 v8::AccessType type, |
8645 Local<Value> data) { | 8633 Local<Value> data) { |
8646 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || | 8634 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || |
8647 allowed_access_type[type]; | 8635 allowed_access_type[type]; |
(...skipping 5593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14241 CHECK(f2->Call(global, 0, NULL)->Equals(v8_num(1))); | 14229 CHECK(f2->Call(global, 0, NULL)->Equals(v8_num(1))); |
14242 } | 14230 } |
14243 | 14231 |
14244 // Same for g1 and g2. | 14232 // Same for g1 and g2. |
14245 CHECK(g1->Call(global, 0, NULL)->Equals(v8_num(1))); | 14233 CHECK(g1->Call(global, 0, NULL)->Equals(v8_num(1))); |
14246 for (int i = 0; i < 4; i++) { | 14234 for (int i = 0; i < 4; i++) { |
14247 CHECK(g2->Call(global, 0, NULL)->Equals(v8_num(1))); | 14235 CHECK(g2->Call(global, 0, NULL)->Equals(v8_num(1))); |
14248 } | 14236 } |
14249 | 14237 |
14250 // Detach the global and turn on access check. | 14238 // Detach the global and turn on access check. |
| 14239 Local<Object> hidden_global = Local<Object>::Cast( |
| 14240 context->Global()->GetPrototype()); |
14251 context->DetachGlobal(); | 14241 context->DetachGlobal(); |
14252 context->Global()->TurnOnAccessCheck(); | 14242 hidden_global->TurnOnAccessCheck(); |
14253 | 14243 |
14254 // Failing access check to property get results in undefined. | 14244 // Failing access check to property get results in undefined. |
14255 CHECK(f1->Call(global, 0, NULL)->IsUndefined()); | 14245 CHECK(f1->Call(global, 0, NULL)->IsUndefined()); |
14256 CHECK(f2->Call(global, 0, NULL)->IsUndefined()); | 14246 CHECK(f2->Call(global, 0, NULL)->IsUndefined()); |
14257 | 14247 |
14258 // Failing access check to function call results in exception. | 14248 // Failing access check to function call results in exception. |
14259 CHECK(g1->Call(global, 0, NULL).IsEmpty()); | 14249 CHECK(g1->Call(global, 0, NULL).IsEmpty()); |
14260 CHECK(g2->Call(global, 0, NULL).IsEmpty()); | 14250 CHECK(g2->Call(global, 0, NULL).IsEmpty()); |
14261 | 14251 |
14262 // No failing access check when just returning a constant. | 14252 // No failing access check when just returning a constant. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14326 } | 14316 } |
14327 | 14317 |
14328 // Same for g1 and g2. | 14318 // Same for g1 and g2. |
14329 CHECK(g1->Call(global, 0, NULL)->Equals(v8_num(1))); | 14319 CHECK(g1->Call(global, 0, NULL)->Equals(v8_num(1))); |
14330 for (int i = 0; i < 4; i++) { | 14320 for (int i = 0; i < 4; i++) { |
14331 CHECK(g2->Call(global, 0, NULL)->Equals(v8_num(1))); | 14321 CHECK(g2->Call(global, 0, NULL)->Equals(v8_num(1))); |
14332 } | 14322 } |
14333 | 14323 |
14334 // Detach the global and turn on access check now blocking access to property | 14324 // Detach the global and turn on access check now blocking access to property |
14335 // a and function h. | 14325 // a and function h. |
| 14326 Local<Object> hidden_global = Local<Object>::Cast( |
| 14327 context->Global()->GetPrototype()); |
14336 context->DetachGlobal(); | 14328 context->DetachGlobal(); |
14337 context->Global()->TurnOnAccessCheck(); | 14329 hidden_global->TurnOnAccessCheck(); |
14338 | 14330 |
14339 // Failing access check to property get results in undefined. | 14331 // Failing access check to property get results in undefined. |
14340 CHECK(f1->Call(global, 0, NULL)->IsUndefined()); | 14332 CHECK(f1->Call(global, 0, NULL)->IsUndefined()); |
14341 CHECK(f2->Call(global, 0, NULL)->IsUndefined()); | 14333 CHECK(f2->Call(global, 0, NULL)->IsUndefined()); |
14342 | 14334 |
14343 // Failing access check to function call results in exception. | 14335 // Failing access check to function call results in exception. |
14344 CHECK(g1->Call(global, 0, NULL).IsEmpty()); | 14336 CHECK(g1->Call(global, 0, NULL).IsEmpty()); |
14345 CHECK(g2->Call(global, 0, NULL).IsEmpty()); | 14337 CHECK(g2->Call(global, 0, NULL).IsEmpty()); |
14346 | 14338 |
14347 // No failing access check when just returning a constant. | 14339 // No failing access check when just returning a constant. |
14348 CHECK(h->Call(global, 0, NULL)->Equals(v8_num(1))); | 14340 CHECK(h->Call(global, 0, NULL)->Equals(v8_num(1))); |
14349 | 14341 |
14350 // Now compile the source again. And get the newly compiled functions, except | 14342 // Now compile the source again. And get the newly compiled functions, except |
14351 // for h for which access is blocked. | 14343 // for h for which access is blocked. |
14352 CompileRun(source); | 14344 CompileRun(source); |
14353 f1 = Local<Function>::Cast(context->Global()->Get(v8_str("f1"))); | 14345 f1 = Local<Function>::Cast(hidden_global->Get(v8_str("f1"))); |
14354 f2 = Local<Function>::Cast(context->Global()->Get(v8_str("f2"))); | 14346 f2 = Local<Function>::Cast(hidden_global->Get(v8_str("f2"))); |
14355 g1 = Local<Function>::Cast(context->Global()->Get(v8_str("g1"))); | 14347 g1 = Local<Function>::Cast(hidden_global->Get(v8_str("g1"))); |
14356 g2 = Local<Function>::Cast(context->Global()->Get(v8_str("g2"))); | 14348 g2 = Local<Function>::Cast(hidden_global->Get(v8_str("g2"))); |
14357 CHECK(context->Global()->Get(v8_str("h"))->IsUndefined()); | 14349 CHECK(hidden_global->Get(v8_str("h"))->IsUndefined()); |
14358 | 14350 |
14359 // Failing access check to property get results in undefined. | 14351 // Failing access check to property get results in undefined. |
14360 CHECK(f1->Call(global, 0, NULL)->IsUndefined()); | 14352 CHECK(f1->Call(global, 0, NULL)->IsUndefined()); |
14361 CHECK(f2->Call(global, 0, NULL)->IsUndefined()); | 14353 CHECK(f2->Call(global, 0, NULL)->IsUndefined()); |
14362 | 14354 |
14363 // Failing access check to function call results in exception. | 14355 // Failing access check to function call results in exception. |
14364 CHECK(g1->Call(global, 0, NULL).IsEmpty()); | 14356 CHECK(g1->Call(global, 0, NULL).IsEmpty()); |
14365 CHECK(g2->Call(global, 0, NULL).IsEmpty()); | 14357 CHECK(g2->Call(global, 0, NULL).IsEmpty()); |
14366 } | 14358 } |
14367 | 14359 |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15214 v8::Handle<v8::String> foo_string = | 15206 v8::Handle<v8::String> foo_string = |
15215 v8::String::NewFromUtf8(context->GetIsolate(), "foo"); | 15207 v8::String::NewFromUtf8(context->GetIsolate(), "foo"); |
15216 obj->Set(foo_string, func_templ->GetFunction()); | 15208 obj->Set(foo_string, func_templ->GetFunction()); |
15217 v8::Handle<v8::Object> obj_clone = obj->Clone(); | 15209 v8::Handle<v8::Object> obj_clone = obj->Clone(); |
15218 obj_clone->Set(foo_string, | 15210 obj_clone->Set(foo_string, |
15219 v8::String::NewFromUtf8(context->GetIsolate(), "Hello")); | 15211 v8::String::NewFromUtf8(context->GetIsolate(), "Hello")); |
15220 CHECK(!obj->Get(foo_string)->IsUndefined()); | 15212 CHECK(!obj->Get(foo_string)->IsUndefined()); |
15221 } | 15213 } |
15222 | 15214 |
15223 | 15215 |
15224 // Regression test for http://crbug.com/16276. | |
15225 THREADED_TEST(Regress16276) { | |
15226 LocalContext context; | |
15227 v8::HandleScope scope(context->GetIsolate()); | |
15228 // Force the IC in f to be a dictionary load IC. | |
15229 CompileRun("function f(obj) { return obj.x; }\n" | |
15230 "var obj = { x: { foo: 42 }, y: 87 };\n" | |
15231 "var x = obj.x;\n" | |
15232 "delete obj.y;\n" | |
15233 "for (var i = 0; i < 5; i++) f(obj);"); | |
15234 // Detach the global object to make 'this' refer directly to the | |
15235 // global object (not the proxy), and make sure that the dictionary | |
15236 // load IC doesn't mess up loading directly from the global object. | |
15237 context->DetachGlobal(); | |
15238 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value()); | |
15239 } | |
15240 | |
15241 static void CheckElementValue(i::Isolate* isolate, | 15216 static void CheckElementValue(i::Isolate* isolate, |
15242 int expected, | 15217 int expected, |
15243 i::Handle<i::Object> obj, | 15218 i::Handle<i::Object> obj, |
15244 int offset) { | 15219 int offset) { |
15245 i::Object* element = obj->GetElement(isolate, offset)->ToObjectChecked(); | 15220 i::Object* element = obj->GetElement(isolate, offset)->ToObjectChecked(); |
15246 CHECK_EQ(expected, i::Smi::cast(element)->value()); | 15221 CHECK_EQ(expected, i::Smi::cast(element)->value()); |
15247 } | 15222 } |
15248 | 15223 |
15249 | 15224 |
15250 THREADED_TEST(PixelArray) { | 15225 THREADED_TEST(PixelArray) { |
(...skipping 5621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20872 } | 20847 } |
20873 for (int i = 0; i < runs; i++) { | 20848 for (int i = 0; i < runs; i++) { |
20874 Local<String> expected; | 20849 Local<String> expected; |
20875 if (i != 0) { | 20850 if (i != 0) { |
20876 CHECK_EQ(v8_str("escape value"), values[i]); | 20851 CHECK_EQ(v8_str("escape value"), values[i]); |
20877 } else { | 20852 } else { |
20878 CHECK(values[i].IsEmpty()); | 20853 CHECK(values[i].IsEmpty()); |
20879 } | 20854 } |
20880 } | 20855 } |
20881 } | 20856 } |
OLD | NEW |