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

Unified Diff: test/cctest/test-api.cc

Issue 12673: Change implementation of eval to make an exact distinction between direct eva... (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 side-by-side diff with in-line comments
Download patch
Index: test/cctest/test-api.cc
===================================================================
--- test/cctest/test-api.cc (revision 854)
+++ test/cctest/test-api.cc (working copy)
@@ -4018,27 +4018,41 @@
}
-THREADED_TEST(Eval) {
+THREADED_TEST(EvalAliasedDynamic) {
v8::HandleScope scope;
LocalContext current;
- // Test that un-aliased eval uses local context.
+ // This sets 'global' to the real global object (as opposed to the
+ // proxy). It is highly implementation dependent, so take care.
+ current->Global()->Set(v8_str("global"), current->Global()->GetPrototype());
+
+ // Tests where aliased eval can only be resolved dynamically.
Local<Script> script =
- Script::Compile(v8_str("foo = 0;"
- "(function() {"
+ Script::Compile(v8_str("function f(x) { "
" var foo = 2;"
- " return eval('foo');"
- "})();"));
- Local<Value> result = script->Run();
- CHECK_EQ(2, result->Int32Value());
+ " with (x) { return eval('foo'); }"
+ "}"
+ "foo = 0;"
+ "result1 = f(new Object());"
+ "result2 = f(global);"
+ "var x = new Object();"
+ "x.eval = function(x) { return 1; };"
+ "result3 = f(x);"));
+ script->Run();
+ CHECK_EQ(2, current->Global()->Get(v8_str("result1"))->Int32Value());
+ CHECK_EQ(0, current->Global()->Get(v8_str("result2"))->Int32Value());
+ CHECK_EQ(1, current->Global()->Get(v8_str("result3"))->Int32Value());
- // Test that un-aliased eval has right this.
+ v8::TryCatch try_catch;
script =
- Script::Compile(v8_str("function MyObject() { this.self = eval('this'); }"
- "var o = new MyObject();"
- "o === o.self"));
- result = script->Run();
- CHECK(result->IsTrue());
+ Script::Compile(v8_str("function f(x) { "
+ " var bar = 2;"
+ " with (x) { return eval('bar'); }"
+ "}"
+ "f(global)"));
+ script->Run();
+ CHECK(try_catch.HasCaught());
+ try_catch.Reset();
}
« src/codegen-ia32.cc ('K') | « src/v8natives.js ('k') | test/mjsunit/eval.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698