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 ce22d9a59c160f01a62952e5ea69f8778d9ce8f9..4fa4d5adae8e978295766dfe92b9aa9b4f75198d 100644 |
| --- a/test/cctest/test-api-fast-accessor-builder.cc |
| +++ b/test/cctest/test-api-fast-accessor-builder.cc |
| @@ -60,8 +60,24 @@ static void NativePropertyAccessor( |
| info.GetReturnValue().Set(v8_num(123)); |
| } |
| +const char* kWatermarkProperty = "watermark"; |
| + |
| } // anonymous namespace |
| +void CheckImplicitParameters(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| + v8::Isolate* isolate = info.GetIsolate(); |
| + CHECK_NOT_NULL(isolate); |
| + |
| + auto context = isolate->GetCurrentContext(); |
| + CHECK(!context.IsEmpty()); |
| + |
| + // The context must point to the same isolate, this should be enough to |
| + // validate the context, mainly to prevent having a random object instead. |
| + CHECK_EQ(isolate, context->GetIsolate()); |
| + CHECK(info.Data()->IsUndefined()); |
| + |
| + CHECK(info.Holder()->Has(v8_str(kWatermarkProperty))); |
| +} |
| // Build a simple "fast accessor" and verify that it is being called. |
| TEST(FastAccessor) { |
| @@ -300,16 +316,19 @@ TEST(FastAccessorLoad) { |
| } |
| void ApiCallbackInt(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| + CheckImplicitParameters(info); |
| info.GetReturnValue().Set(12345); |
| } |
| const char* kApiCallbackStringValue = |
| "Hello World! Bizarro C++ world, actually."; |
| void ApiCallbackString(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| + CheckImplicitParameters(info); |
| info.GetReturnValue().Set(v8_str(kApiCallbackStringValue)); |
| } |
| void ApiCallbackParam(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| + CheckImplicitParameters(info); |
| CHECK_EQ(1, info.Length()); |
| CHECK(info[0]->IsNumber()); |
| info.GetReturnValue().Set(info[0]); |
| @@ -348,6 +367,16 @@ TEST(FastAccessorCallback) { |
| isolate, NativePropertyAccessor, builder)); |
| } |
| + // Add dummy property to validate the holder. |
| + { |
| + auto builder = v8::experimental::FastAccessorBuilder::New(isolate); |
| + builder->ReturnValue(builder->IntegerConstant(537)); |
| + |
| + foo->SetAccessorProperty(v8_str(kWatermarkProperty), |
| + v8::FunctionTemplate::NewWithFastHandler( |
| + isolate, NativePropertyAccessor, builder)); |
| + } |
|
vogelheim
2016/07/19 14:44:58
I think this is a bit more complex than necessary.
|
| + |
| // Create an instance. |
| v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); |
| CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); |