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

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

Issue 111613003: Load the global proxy from the context of the target function. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: hydrogen Created 7 years 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
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 91f37367dae9d0ec815cbd4738bc62484e1df80f..b8ce1a83b972fb9c8911265c9261b08e640b6023 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -8642,22 +8642,31 @@ TEST(DetachedAccesses) {
env1->SetSecurityToken(foo);
env2->SetSecurityToken(foo);
+ env1->Global()->Set(v8_str("x"), v8_str("env1_x"));
+
{
v8::Context::Scope scope(env2);
+ env2->Global()->Set(v8_str("x"), v8_str("env2_x"));
CompileRun(
- "var x = 'x';"
- "function get_x() { return this.x; }"
- "function get_x_w() { return get_x(); }"
+ "function bound_x() { return x; }"
+ "function get_x() { return this.x; }"
+ "function get_x_w() { return (function() {return this.x;})(); }"
+ "function closure() { return [bound_x(), get_x(), get_x_w()]; }"
"");
+ env1->Global()->Set(v8_str("bound_x"), CompileRun("bound_x"));
env1->Global()->Set(v8_str("get_x"), CompileRun("get_x"));
env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w"));
}
+ CompileRun("function outer_closure() { return closure(); }");
+
Local<Object> env2_global = env2->Global();
env2_global->TurnOnAccessCheck();
env2->DetachGlobal();
Local<Value> result;
+ result = CompileRun("bound_x()");
+ CHECK_EQ(v8_str("env2_x"), result);
result = CompileRun("get_x()");
CHECK(result->IsUndefined());
result = CompileRun("get_x_w()");
@@ -8671,13 +8680,56 @@ TEST(DetachedAccesses) {
env2->SetSecurityToken(foo);
{
v8::Context::Scope scope(env2);
- CompileRun("var x = 'x2';");
+ env2->Global()->Set(v8_str("x"), v8_str("env3_x"));
+ env2->Global()->Set(v8_str("env1"), env1->Global());
+ result = CompileRun(
+ "results = [];"
+ "for (var i = 0; i < 4; i++ ) {"
+ " results.push(env1.bound_x());"
+ " results.push(env1.get_x());"
+ " results.push(env1.get_x_w());"
+ "}"
+ "results");
+ Local<v8::Array> results = Local<v8::Array>::Cast(result);
+ CHECK_EQ(12, results->Length());
+ for (int i = 0; i < 12; i += 3) {
+ CHECK_EQ(v8_str("env2_x"), results->Get(i + 0));
+ CHECK_EQ(v8_str("env1_x"), results->Get(i + 1));
+ CHECK_EQ(v8_str("env3_x"), results->Get(i + 2));
+ }
}
- result = CompileRun("get_x()");
- CHECK(result->IsUndefined());
- result = CompileRun("get_x_w()");
- CHECK_EQ(v8_str("x2"), result);
+ result = CompileRun(
+ "results = [];"
+ "for (var i = 0; i < 4; i++ ) {"
+ " results.push(bound_x());"
+ " results.push(get_x());"
+ " results.push(get_x_w());"
+ "}"
+ "results");
+ Local<v8::Array> results = Local<v8::Array>::Cast(result);
+ CHECK_EQ(12, results->Length());
+ for (int i = 0; i < 12; i += 3) {
+ CHECK_EQ(v8_str("env2_x"), results->Get(i + 0));
+ CHECK_EQ(v8_str("env3_x"), results->Get(i + 1));
+ CHECK_EQ(v8_str("env3_x"), results->Get(i + 2));
+ }
+
+ result = CompileRun(
+ "results = [];"
+ "for (var i = 0; i < 4; i++ ) {"
+ " results.push(this.bound_x());"
+ " results.push(this.get_x());"
+ " results.push(this.get_x_w());"
+ "}"
+ "results");
+ results = Local<v8::Array>::Cast(result);
+ CHECK_EQ(12, results->Length());
+ for (int i = 0; i < 12; i += 3) {
+ CHECK_EQ(v8_str("env2_x"), results->Get(i + 0));
+ CHECK_EQ(v8_str("env1_x"), results->Get(i + 1));
+ CHECK_EQ(v8_str("env3_x"), results->Get(i + 2));
+ }
}
@@ -19844,11 +19896,10 @@ THREADED_TEST(ForeignFunctionReceiver) {
CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]")));
CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]")));
- // TODO(1547): Make the following also return "i".
// Calling with environment record as base.
- TestReceiver(o, context->Global(), "func()");
+ TestReceiver(i, foreign_context->Global(), "func()");
// Calling with no base.
- TestReceiver(o, context->Global(), "(1,func)()");
+ TestReceiver(i, foreign_context->Global(), "(1,func)()");
}

Powered by Google App Engine
This is Rietveld 408576698