Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 3168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3179 | 3179 |
| 3180 // Check that env1.prop still exists. | 3180 // Check that env1.prop still exists. |
| 3181 Local<Value> v = env1->Global()->Get(v8_str("prop")); | 3181 Local<Value> v = env1->Global()->Get(v8_str("prop")); |
| 3182 CHECK(v->IsNumber()); | 3182 CHECK(v->IsNumber()); |
| 3183 CHECK_EQ(3, v->Int32Value()); | 3183 CHECK_EQ(3, v->Int32Value()); |
| 3184 | 3184 |
| 3185 env2.Dispose(); | 3185 env2.Dispose(); |
| 3186 } | 3186 } |
| 3187 | 3187 |
| 3188 | 3188 |
| 3189 THREADED_TEST(CrossDomainIsPropertyEnumerable) { | |
| 3190 v8::HandleScope handle_scope; | |
| 3191 LocalContext env1; | |
| 3192 v8::Persistent<Context> env2 = Context::New(); | |
| 3193 | |
| 3194 Local<Value> foo = v8_str("foo"); | |
| 3195 Local<Value> bar = v8_str("bar"); | |
| 3196 | |
| 3197 // Set to the same domain. | |
| 3198 env1->SetSecurityToken(foo); | |
| 3199 env2->SetSecurityToken(foo); | |
| 3200 | |
| 3201 env1->Global()->Set(v8_str("prop"), v8_num(3)); | |
| 3202 env2->Global()->Set(v8_str("env1"), env1->Global()); | |
| 3203 | |
| 3204 // env1.prop is enumerable in env2. | |
| 3205 Local<String> test = v8_str("propertyIsEnumerable.call(env1, 'prop')"); | |
| 3206 { | |
| 3207 Context::Scope scope_env2(env2); | |
| 3208 Local<Value> result = Script::Compile(test)->Run(); | |
| 3209 CHECK(result->IsTrue()); | |
| 3210 } | |
| 3211 | |
| 3212 // Change env2 to a different domain and test again. | |
| 3213 env2->SetSecurityToken(bar); | |
| 3214 { | |
| 3215 Context::Scope scope_env2(env2); | |
| 3216 Local<Value> result = Script::Compile(test)->Run(); | |
| 3217 CHECK(result->IsFalse()); | |
| 3218 } | |
| 3219 | |
| 3220 env2.Dispose(); | |
| 3221 } | |
| 3222 | |
| 3223 | |
| 3189 THREADED_TEST(CrossDomainForIn) { | 3224 THREADED_TEST(CrossDomainForIn) { |
| 3190 v8::HandleScope handle_scope; | 3225 v8::HandleScope handle_scope; |
| 3191 LocalContext env1; | 3226 LocalContext env1; |
| 3192 v8::Persistent<Context> env2 = Context::New(); | 3227 v8::Persistent<Context> env2 = Context::New(); |
| 3193 | 3228 |
| 3194 Local<Value> foo = v8_str("foo"); | 3229 Local<Value> foo = v8_str("foo"); |
| 3195 Local<Value> bar = v8_str("bar"); | 3230 Local<Value> bar = v8_str("bar"); |
| 3196 | 3231 |
| 3197 // Set to the same domain. | 3232 // Set to the same domain. |
| 3198 env1->SetSecurityToken(foo); | 3233 env1->SetSecurityToken(foo); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3335 IndexedAccessBlocker); | 3370 IndexedAccessBlocker); |
| 3336 | 3371 |
| 3337 // Add an accessor accessible by cross-domain JS code. | 3372 // Add an accessor accessible by cross-domain JS code. |
| 3338 global_template->SetAccessor( | 3373 global_template->SetAccessor( |
| 3339 v8_str("accessible_prop"), | 3374 v8_str("accessible_prop"), |
| 3340 EchoGetter, EchoSetter, | 3375 EchoGetter, EchoSetter, |
| 3341 v8::Handle<Value>(), | 3376 v8::Handle<Value>(), |
| 3342 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); | 3377 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); |
| 3343 | 3378 |
| 3344 // Add an accessor that is not accessible by cross-domain JS code. | 3379 // Add an accessor that is not accessible by cross-domain JS code. |
| 3345 global_template->SetAccessor(v8_str("blocked_access_prop"), | 3380 global_template->SetAccessor(v8_str("blocked_prop"), |
| 3346 UnreachableGetter, UnreachableSetter, | 3381 UnreachableGetter, UnreachableSetter, |
| 3347 v8::Handle<Value>(), | 3382 v8::Handle<Value>(), |
| 3348 v8::DEFAULT); | 3383 v8::DEFAULT); |
| 3349 | 3384 |
| 3350 // Create an environment | 3385 // Create an environment |
| 3351 v8::Persistent<Context> context0 = Context::New(NULL, global_template); | 3386 v8::Persistent<Context> context0 = Context::New(NULL, global_template); |
| 3352 context0->Enter(); | 3387 context0->Enter(); |
| 3353 | 3388 |
| 3354 v8::Handle<v8::Object> global0 = context0->Global(); | 3389 v8::Handle<v8::Object> global0 = context0->Global(); |
| 3355 | 3390 |
| 3356 v8::HandleScope scope1; | 3391 v8::HandleScope scope1; |
| 3357 | 3392 |
| 3358 v8::Persistent<Context> context1 = Context::New(); | 3393 v8::Persistent<Context> context1 = Context::New(); |
| 3359 context1->Enter(); | 3394 context1->Enter(); |
| 3360 | 3395 |
| 3361 v8::Handle<v8::Object> global1 = context1->Global(); | 3396 v8::Handle<v8::Object> global1 = context1->Global(); |
| 3362 global1->Set(v8_str("other"), global0); | 3397 global1->Set(v8_str("other"), global0); |
| 3363 | 3398 |
| 3364 v8::Handle<Value> value; | 3399 v8::Handle<Value> value; |
| 3365 | 3400 |
| 3366 // Access blocked property | 3401 // Access blocked property |
| 3367 value = v8_compile("other.blocked_prop = 1")->Run(); | 3402 value = v8_compile("other.blocked_prop = 1")->Run(); |
| 3368 value = v8_compile("other.blocked_prop")->Run(); | 3403 value = v8_compile("other.blocked_prop")->Run(); |
| 3369 CHECK(value->IsUndefined()); | 3404 CHECK(value->IsUndefined()); |
| 3370 | 3405 |
| 3406 value = v8_compile("propertyIsEnumerable.call(other, 'blocked_prop')")->Run(); | |
| 3407 CHECK(value->IsBoolean()); | |
| 3408 CHECK_EQ(false, value->BooleanValue()); | |
| 3409 | |
| 3371 // Access accessible property | 3410 // Access accessible property |
| 3372 value = v8_compile("other.accessible_prop = 3")->Run(); | 3411 value = v8_compile("other.accessible_prop = 3")->Run(); |
| 3373 CHECK(value->IsNumber()); | 3412 CHECK(value->IsNumber()); |
| 3374 CHECK_EQ(3, value->Int32Value()); | 3413 CHECK_EQ(3, value->Int32Value()); |
| 3375 | 3414 |
| 3376 value = v8_compile("other.accessible_prop")->Run(); | 3415 value = v8_compile("other.accessible_prop")->Run(); |
| 3377 CHECK(value->IsNumber()); | 3416 CHECK(value->IsNumber()); |
| 3378 CHECK_EQ(3, value->Int32Value()); | 3417 CHECK_EQ(3, value->Int32Value()); |
| 3379 | 3418 |
| 3419 value = | |
| 3420 v8_compile("propertyIsEnumerable.call(other, 'accessible_prop')")->Run(); | |
| 3421 CHECK(value->IsBoolean()); | |
| 3422 CHECK_EQ(true, value->BooleanValue()); | |
| 3423 | |
| 3424 Local<Value> result = | |
| 3425 CompileRun("(function(){var obj = {'__proto__':other};" | |
| 3426 "for (var p in obj)" | |
| 3427 " if (p == 'blocked_prop') return false;" | |
|
Mads Ager (chromium)
2008/10/28 20:02:38
We should also check that accessible_prop is actua
| |
| 3428 "return true;})()"); | |
| 3429 CHECK(result->IsTrue()); | |
| 3430 | |
| 3380 context1->Exit(); | 3431 context1->Exit(); |
| 3381 context0->Exit(); | 3432 context0->Exit(); |
| 3382 context1.Dispose(); | 3433 context1.Dispose(); |
| 3383 context0.Dispose(); | 3434 context0.Dispose(); |
| 3384 } | 3435 } |
| 3385 | 3436 |
| 3386 | 3437 |
| 3387 static v8::Handle<Value> ConstTenGetter(Local<String> name, | 3438 static v8::Handle<Value> ConstTenGetter(Local<String> name, |
| 3388 const AccessorInfo& info) { | 3439 const AccessorInfo& info) { |
| 3389 return v8_num(10); | 3440 return v8_num(10); |
| (...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5068 int elmc1 = 2; | 5119 int elmc1 = 2; |
| 5069 const char* elmv1[] = {"a", "b"}; | 5120 const char* elmv1[] = {"a", "b"}; |
| 5070 CheckProperties(elms->Get(v8::Integer::New(1)), elmc1, elmv1); | 5121 CheckProperties(elms->Get(v8::Integer::New(1)), elmc1, elmv1); |
| 5071 int elmc2 = 3; | 5122 int elmc2 = 3; |
| 5072 const char* elmv2[] = {"0", "1", "2"}; | 5123 const char* elmv2[] = {"0", "1", "2"}; |
| 5073 CheckProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2); | 5124 CheckProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2); |
| 5074 int elmc3 = 4; | 5125 int elmc3 = 4; |
| 5075 const char* elmv3[] = {"w", "z", "x", "y"}; | 5126 const char* elmv3[] = {"w", "z", "x", "y"}; |
| 5076 CheckProperties(elms->Get(v8::Integer::New(3)), elmc3, elmv3); | 5127 CheckProperties(elms->Get(v8::Integer::New(3)), elmc3, elmv3); |
| 5077 } | 5128 } |
| OLD | NEW |