Index: test/cctest/test-api-accessors.cc |
diff --git a/test/cctest/test-api-accessors.cc b/test/cctest/test-api-accessors.cc |
index cc0c7efb5ff2985106e5f7462f8c4259a1825b06..921f54d466a53d610f28c9d27282dc2e3b970549 100644 |
--- a/test/cctest/test-api-accessors.cc |
+++ b/test/cctest/test-api-accessors.cc |
@@ -249,6 +249,89 @@ TEST(CachedAccessorCrankshaft) { |
ExpectInt32("g()", 789); |
} |
+TEST(CachedAccessorOnGlobalObject) { |
+ i::FLAG_allow_natives_syntax = true; |
+ LocalContext env; |
+ v8::Isolate* isolate = env->GetIsolate(); |
+ v8::HandleScope scope(isolate); |
+ |
+ v8::Local<v8::FunctionTemplate> templ = |
+ v8::FunctionTemplate::New(CcTest::isolate()); |
+ v8::Local<v8::ObjectTemplate> object_template = templ->InstanceTemplate(); |
+ v8::Local<v8::Private> priv = |
+ v8::Private::ForApi(isolate, v8_str("Foo#draft")); |
+ |
+ object_template->SetAccessorProperty( |
+ v8_str("draft"), |
+ v8::FunctionTemplate::NewWithCache(isolate, UnreachableCallback, priv, |
+ v8::Local<v8::Value>())); |
+ |
+ v8::Local<v8::Context> ctx = |
+ v8::Context::New(CcTest::isolate(), nullptr, object_template); |
+ v8::Local<v8::Object> obj = ctx->Global(); |
+ |
+ // Install the private property on the instance. |
+ CHECK(obj->SetPrivate(isolate->GetCurrentContext(), priv, |
+ v8::Undefined(isolate)) |
+ .FromJust()); |
+ |
+ { |
+ v8::Context::Scope context_scope(ctx); |
+ |
+ // Access surrogate accessor. |
+ ExpectUndefined("draft"); |
+ |
+ // Set hidden property. |
+ CHECK(obj->SetPrivate(env.local(), priv, v8::Integer::New(isolate, 123)) |
+ .FromJust()); |
+ |
+ // Test ICs. |
+ CompileRun( |
+ "function f() {" |
+ " var x;" |
+ " for (var i = 0; i < 100; i++) {" |
+ " x = draft;" |
+ " }" |
+ " return x;" |
+ "}"); |
+ |
+ ExpectInt32("f()", 123); |
+ |
+ // Reset hidden property. |
+ CHECK(obj->SetPrivate(env.local(), priv, v8::Integer::New(isolate, 456)) |
+ .FromJust()); |
+ |
+ // Test Crankshaft. |
+ CompileRun("%OptimizeFunctionOnNextCall(f);"); |
+ |
+ ExpectInt32("f()", 456); |
+ |
+ CHECK(obj->SetPrivate(env.local(), priv, v8::Integer::New(isolate, 456)) |
+ .FromJust()); |
+ // Test non-global ICs. |
+ CompileRun( |
+ "var x = this;" |
+ "function g() {" |
+ " var r = 0;" |
+ " for (var i = 0; i < 100; i++) {" |
+ " r = x.draft;" |
+ " }" |
+ " return r;" |
+ "}"); |
+ |
+ ExpectInt32("g()", 456); |
+ |
+ // Reset hidden property. |
+ CHECK(obj->SetPrivate(env.local(), priv, v8::Integer::New(isolate, 789)) |
+ .FromJust()); |
+ |
+ // Test non-global access in Crankshaft. |
+ CompileRun("%OptimizeFunctionOnNextCall(g);"); |
+ |
+ ExpectInt32("g()", 789); |
+ } |
+} |
+ |
namespace { |
static void Setter(v8::Local<v8::String> name, v8::Local<v8::Value> value, |