Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 8d9b32b05c889fbb14c562ac82705e7620e98134..f01ee34af7126fd6a227e897dcf04b51cdcfeb13 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -19787,4 +19787,39 @@ TEST(JSONStringifyAccessCheck) { |
} |
+TEST(Bug2778) { |
+ // Check that Object.observe includes access check. |
+ i::FLAG_harmony_observation = true; |
+ v8::V8::Initialize(); |
+ v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
+ v8::HandleScope scope(isolate); |
+ // Create an ObjectTemplate for global objects and install access |
+ // check callbacks that will block access. |
+ v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
+ global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked, |
+ IndexAccessAlwaysBlocked); |
+ |
+ // Create a context and set an x property on it's global object. |
+ LocalContext outer_context(NULL, global_template); |
+ v8::Handle<v8::Object> outer_global = outer_context->Global(); |
+ outer_global->Set(v8_str("x"), v8_num(42)); |
+ |
+ // Enter a new context. |
+ v8::Handle<v8::Context> inner_context = v8::Context::New(isolate); |
+ { v8::Context::Scope inner(inner_context); |
+ v8::Handle<v8::Object> inner_global = inner_context->Global(); |
+ inner_global->Set(v8_str("other"), outer_global); |
+ v8::Handle<v8::FunctionTemplate> unreachable = |
+ v8::FunctionTemplate::New(UnreachableCallback); |
+ inner_global->Set(v8_str("unreachable"), unreachable->GetFunction()); |
+ ExpectUndefined("other.x"); // Verify that access checks are in place. |
+ CompileRun("Object.observe(other, unreachable);"); // Install observer. |
+ } |
+ |
+ ExpectInt32("x", 42); |
+ // This must not be observable by the observer set up in the inner context. |
+ CompileRun("var a = 123;"); |
+} |
+ |
+ |
#endif // WIN32 |