Chromium Code Reviews| Index: test/cctest/test-api-fast-accessor-builder.cc |
| diff --git a/test/cctest/test-api-fast-accessor-builder.cc b/test/cctest/test-api-fast-accessor-builder.cc |
| index 349331a6b15f4ba56a867d46b50f7494c19da1a2..73cf1fd796920d0190f5adb48374763db675edc4 100644 |
| --- a/test/cctest/test-api-fast-accessor-builder.cc |
| +++ b/test/cctest/test-api-fast-accessor-builder.cc |
| @@ -113,13 +113,19 @@ TEST(FastAccessor) { |
| ExpectInt32("barf()", 124); // Call via warmed-up callsite. |
| } |
| - |
| void AddInternalFieldAccessor(v8::Isolate* isolate, |
| v8::Local<v8::Template> templ, const char* name, |
| - int field_no) { |
| + int field_no, bool useUnsafeLoader) { |
| auto builder = v8::experimental::FastAccessorBuilder::New(isolate); |
| - builder->ReturnValue( |
| - builder->LoadInternalField(builder->GetReceiver(), field_no)); |
| + |
| + if (useUnsafeLoader) { |
| + builder->ReturnValue( |
| + builder->LoadInternalFieldUnsafe(builder->GetReceiver(), field_no)); |
| + } else { |
| + builder->ReturnValue( |
| + builder->LoadInternalField(builder->GetReceiver(), field_no)); |
| + } |
| + |
| templ->SetAccessorProperty(v8_str(name), |
| v8::FunctionTemplate::NewWithFastHandler( |
| isolate, NativePropertyAccessor, builder)); |
| @@ -137,9 +143,42 @@ TEST(FastAccessorWithInternalField) { |
| v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); |
| foo->SetInternalFieldCount(3); |
| - AddInternalFieldAccessor(isolate, foo, "field0", 0); |
| - AddInternalFieldAccessor(isolate, foo, "field1", 1); |
| - AddInternalFieldAccessor(isolate, foo, "field2", 2); |
| + AddInternalFieldAccessor(isolate, foo, "field0", 0, false); |
| + AddInternalFieldAccessor(isolate, foo, "field1", 1, false); |
| + AddInternalFieldAccessor(isolate, foo, "field2", 2, false); |
| + |
| + // Create an instance w/ 3 internal fields, put in a string, a Smi, nothing. |
| + v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); |
| + obj->SetInternalField(0, v8_str("Hi there!")); |
| + obj->SetInternalField(1, v8::Integer::New(isolate, 4321)); |
| + CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); |
| + |
| + // Warmup. |
| + CompileRun(FN_WARMUP("field0", "return obj.field0")); |
| + CompileRun(FN_WARMUP("field1", "return obj.field1")); |
| + CompileRun(FN_WARMUP("field2", "return obj.field2")); |
| + |
| + // Access fields. |
| + ExpectString("field0()", "Hi there!"); |
| + ExpectInt32("field1()", 4321); |
| + ExpectUndefined("field2()"); |
| +} |
| + |
| +// "Fast" accessor that accesses an internal field using the fast(er) but unsafe |
| +// implementation of LoadInternalField. |
| +TEST(FastAccessorLoadInternalFieldUnsafe) { |
|
vogelheim
2016/07/27 09:50:56
nitpick: If we add the Unsafe-with-crash-when-FLAG
Alfonso
2016/07/28 14:39:13
Refactoring away the common part for the 3 tests.
|
| + // Crankshaft support for fast accessors is not implemented; crankshafted |
| + // code uses the slow accessor which breaks this test's expectations. |
| + v8::internal::FLAG_always_opt = false; |
| + LocalContext env; |
| + v8::Isolate* isolate = env->GetIsolate(); |
| + v8::HandleScope scope(isolate); |
| + |
| + v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); |
| + foo->SetInternalFieldCount(3); |
| + AddInternalFieldAccessor(isolate, foo, "field0", 0, true); |
| + AddInternalFieldAccessor(isolate, foo, "field1", 1, true); |
| + AddInternalFieldAccessor(isolate, foo, "field2", 2, true); |
| // Create an instance w/ 3 internal fields, put in a string, a Smi, nothing. |
| v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); |