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

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

Issue 11601: Changing the semantics of cross-frame eval to be compatible with Safari and F... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 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 | Annotate | Revision Log
« no previous file with comments | « src/v8natives.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4000 matching lines...) Expand 10 before | Expand all | Expand 10 after
4011 " if (str.indexOf('#<a Fun>') == -1) return 3;" 4011 " if (str.indexOf('#<a Fun>') == -1) return 3;"
4012 " return 0;" 4012 " return 0;"
4013 " }" 4013 " }"
4014 " return 4;" 4014 " return 4;"
4015 "}" 4015 "}"
4016 "test();"); 4016 "test();");
4017 CHECK_EQ(0, value->Int32Value()); 4017 CHECK_EQ(0, value->Int32Value());
4018 } 4018 }
4019 4019
4020 4020
4021 THREADED_TEST(Eval) {
4022 v8::HandleScope scope;
4023 LocalContext current;
4024
4025 // Test that un-aliased eval uses local context.
4026 Local<Script> script =
4027 Script::Compile(v8_str("foo = 0;"
4028 "(function() {"
4029 " var foo = 2;"
4030 " return eval('foo');"
4031 "})();"));
4032 Local<Value> foo = script->Run();
4033 CHECK_EQ(2, foo->Int32Value());
4034 }
4035
4036
4021 THREADED_TEST(CrossEval) { 4037 THREADED_TEST(CrossEval) {
4022 v8::HandleScope scope; 4038 v8::HandleScope scope;
4023 LocalContext other; 4039 LocalContext other;
4024 LocalContext current; 4040 LocalContext current;
4025 4041
4026 Local<String> token = v8_str("<security token>"); 4042 Local<String> token = v8_str("<security token>");
4027 other->SetSecurityToken(token); 4043 other->SetSecurityToken(token);
4028 current->SetSecurityToken(token); 4044 current->SetSecurityToken(token);
4029 4045
4030 // Setup reference from current to other. 4046 // Setup reference from current to other.
4031 current->Global()->Set(v8_str("other"), other->Global()); 4047 current->Global()->Set(v8_str("other"), other->Global());
4032 4048
4033 // Check that new variables are introduced in other context. 4049 // Check that new variables are introduced in other context.
4034 Local<Script> script = 4050 Local<Script> script =
4035 Script::Compile(v8_str("other.eval('var foo = 1234')")); 4051 Script::Compile(v8_str("other.eval('var foo = 1234')"));
4036 script->Run(); 4052 script->Run();
4037 Local<Value> foo = other->Global()->Get(v8_str("foo")); 4053 Local<Value> foo = other->Global()->Get(v8_str("foo"));
4038 CHECK_EQ(1234, foo->Int32Value()); 4054 CHECK_EQ(1234, foo->Int32Value());
4039 CHECK(!current->Global()->Has(v8_str("foo"))); 4055 CHECK(!current->Global()->Has(v8_str("foo")));
4040 4056
4041 // Check that writing to non-existing properties introduces them in 4057 // Check that writing to non-existing properties introduces them in
4042 // the current context. 4058 // the other context.
4043 script = 4059 script =
4044 Script::Compile(v8_str("other.eval('na = 1234')")); 4060 Script::Compile(v8_str("other.eval('na = 1234')"));
4045 script->Run(); 4061 script->Run();
4046 CHECK_EQ(1234, current->Global()->Get(v8_str("na"))->Int32Value()); 4062 CHECK_EQ(1234, other->Global()->Get(v8_str("na"))->Int32Value());
4047 CHECK(!other->Global()->Has(v8_str("na"))); 4063 CHECK(!current->Global()->Has(v8_str("na")));
4048 4064
4049 // Check that variables in current context are visible in other 4065 // Check that global variables in current context are not visible in other
4050 // context. This must include local variables. 4066 // context.
4067 v8::TryCatch try_catch;
4051 script = 4068 script =
4052 Script::Compile(v8_str("var bar = 42;" 4069 Script::Compile(v8_str("var bar = 42; other.eval('bar');"));
4053 "(function() { "
4054 " var baz = 87;"
4055 " return other.eval('bar + baz');"
4056 "})();"));
4057 Local<Value> result = script->Run(); 4070 Local<Value> result = script->Run();
4058 CHECK_EQ(42 + 87, result->Int32Value()); 4071 CHECK(try_catch.HasCaught());
4072 try_catch.Reset();
4073
4074 // Check that local variables in current context are not visible in other
4075 // context.
4076 script =
4077 Script::Compile(v8_str("(function() { "
4078 " var baz = 87;"
4079 " return other.eval('baz');"
4080 "})();"));
4081 result = script->Run();
4082 CHECK(try_catch.HasCaught());
4083 try_catch.Reset();
4059 4084
4060 // Check that global variables in the other environment are visible 4085 // Check that global variables in the other environment are visible
4061 // when evaluting code. 4086 // when evaluting code.
4062 other->Global()->Set(v8_str("bis"), v8_num(1234)); 4087 other->Global()->Set(v8_str("bis"), v8_num(1234));
4063 script = Script::Compile(v8_str("other.eval('bis')")); 4088 script = Script::Compile(v8_str("other.eval('bis')"));
4064 CHECK_EQ(1234, script->Run()->Int32Value()); 4089 CHECK_EQ(1234, script->Run()->Int32Value());
4090 CHECK(!try_catch.HasCaught());
4065 4091
4066 // Check that the 'this' pointer isn't touched as a result of 4092 // Check that the 'this' pointer points to the global object evaluating
4067 // calling eval across environments. 4093 // code.
4094 other->Global()->Set(v8_str("t"), other->Global());
4095 script = Script::Compile(v8_str("other.eval('this == t')"));
4096 result = script->Run();
4097 CHECK(result->IsTrue());
4098 CHECK(!try_catch.HasCaught());
4099
4100 // Check that variables introduced in with-statement are not visible in
4101 // other context.
4068 script = 4102 script =
4069 Script::Compile(v8_str("var t = this; other.eval('this == t')")); 4103 Script::Compile(v8_str("with({x:2}){other.eval('x')}"));
4070 result = script->Run(); 4104 result = script->Run();
4071 CHECK(result->IsBoolean()); 4105 CHECK(try_catch.HasCaught());
4072 CHECK(result->BooleanValue()); 4106 try_catch.Reset();
4073
4074 // Check that doing a cross eval works from within a global
4075 // with-statement.
4076 script =
4077 Script::Compile(v8_str("other.y = 1;"
4078 "with({x:2}){other.eval('x+y')}"));
4079 result = script->Run();
4080 CHECK_EQ(3, result->Int32Value());
4081 4107
4082 // Check that you cannot use 'eval.call' with another object than the 4108 // Check that you cannot use 'eval.call' with another object than the
4083 // current global object. 4109 // current global object.
4084 v8::TryCatch try_catch;
4085 script = 4110 script =
4086 Script::Compile(v8_str("other.y = 1; eval.call(other, 'y')")); 4111 Script::Compile(v8_str("other.y = 1; eval.call(other, 'y')"));
4087 result = script->Run(); 4112 result = script->Run();
4088 CHECK(try_catch.HasCaught()); 4113 CHECK(try_catch.HasCaught());
4089 } 4114 }
4090 4115
4091 4116
4092 THREADED_TEST(CrossLazyLoad) { 4117 THREADED_TEST(CrossLazyLoad) {
4093 v8::HandleScope scope; 4118 v8::HandleScope scope;
4094 LocalContext other; 4119 LocalContext other;
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after
5215 LocalContext context; 5240 LocalContext context;
5216 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5241 Local<ObjectTemplate> templ = ObjectTemplate::New();
5217 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker, 5242 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker,
5218 IndexedSetAccessBlocker); 5243 IndexedSetAccessBlocker);
5219 templ->Set(v8_str("x"), v8::True()); 5244 templ->Set(v8_str("x"), v8::True());
5220 Local<v8::Object> instance = templ->NewInstance(); 5245 Local<v8::Object> instance = templ->NewInstance();
5221 context->Global()->Set(v8_str("obj"), instance); 5246 context->Global()->Set(v8_str("obj"), instance);
5222 Local<Value> value = CompileRun("obj.x"); 5247 Local<Value> value = CompileRun("obj.x");
5223 CHECK(value->BooleanValue()); 5248 CHECK(value->BooleanValue());
5224 } 5249 }
OLDNEW
« no previous file with comments | « src/v8natives.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698