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

Unified Diff: test/cctest/test-api-fast-accessor-builder.cc

Issue 1474543004: Implement Fast Accessor Builder (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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-fast-accessor-builder.cc
diff --git a/test/cctest/test-api-fast-accessor-builder.cc b/test/cctest/test-api-fast-accessor-builder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..af559959b9b80d965ad21da968bc839925e0bc0c
--- /dev/null
+++ b/test/cctest/test-api-fast-accessor-builder.cc
@@ -0,0 +1,54 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
epertoso 2015/11/25 10:31:16 Could you actually merge this test with test-api-a
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// TODO(jochen): Remove this after the setting is turned on globally.
+#define V8_IMMINENT_DEPRECATION_WARNINGS
+
+#include <stdlib.h>
+
+#include "src/v8.h"
+
+#include "src/api.h"
+#include "test/cctest/cctest.h"
+
+namespace {
+
+static void NativePropertyAccessor(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ info.GetReturnValue().Set(v8_num(123));
+}
+
+} // anonymous namespace
+
+TEST(FastAccessor) {
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
+
+ v8::Local<v8::FunctionTemplate> foo = v8::FunctionTemplate::New(isolate);
+
+ // Native accessor, bar, returns 123.
+ foo->PrototypeTemplate()->SetAccessorProperty(
+ v8_str("bar"),
+ v8::FunctionTemplate::New(isolate, NativePropertyAccessor));
+
+ // Fast accessor, barf, returns 124.
+ auto fab = v8::experimental::FastAccessorBuilder::New(isolate);
+ fab->ReturnValue(fab->IntegerConstant(124));
+ foo->PrototypeTemplate()->SetAccessorProperty(
+ v8_str("barf"), v8::FunctionTemplate::NewWithFastHandler(
+ isolate, NativePropertyAccessor, fab));
+
+ // Install foo on the global object.
+ CHECK(env->Global()
+ ->Set(env.local(), v8_str("foo"),
+ foo->GetFunction(env.local()).ToLocalChecked())
+ .FromJust());
+
+ ExpectInt32("f = new foo(); f.bar", 123);
+ ExpectInt32("f = new foo(); f.barf", 123);
+ ExpectInt32("f = new foo(); f.barf", 123);
+ ExpectInt32("f = new foo(); f.barf", 123);
+ ExpectInt32("f = new foo(); f.barf", 124);
+}

Powered by Google App Engine
This is Rietveld 408576698