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

Side by Side 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 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 unified diff | Download patch
OLDNEW
(Empty)
1 // 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
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // TODO(jochen): Remove this after the setting is turned on globally.
6 #define V8_IMMINENT_DEPRECATION_WARNINGS
7
8 #include <stdlib.h>
9
10 #include "src/v8.h"
11
12 #include "src/api.h"
13 #include "test/cctest/cctest.h"
14
15 namespace {
16
17 static void NativePropertyAccessor(
18 const v8::FunctionCallbackInfo<v8::Value>& info) {
19 info.GetReturnValue().Set(v8_num(123));
20 }
21
22 } // anonymous namespace
23
24 TEST(FastAccessor) {
25 LocalContext env;
26 v8::Isolate* isolate = env->GetIsolate();
27 v8::HandleScope scope(isolate);
28
29 v8::Local<v8::FunctionTemplate> foo = v8::FunctionTemplate::New(isolate);
30
31 // Native accessor, bar, returns 123.
32 foo->PrototypeTemplate()->SetAccessorProperty(
33 v8_str("bar"),
34 v8::FunctionTemplate::New(isolate, NativePropertyAccessor));
35
36 // Fast accessor, barf, returns 124.
37 auto fab = v8::experimental::FastAccessorBuilder::New(isolate);
38 fab->ReturnValue(fab->IntegerConstant(124));
39 foo->PrototypeTemplate()->SetAccessorProperty(
40 v8_str("barf"), v8::FunctionTemplate::NewWithFastHandler(
41 isolate, NativePropertyAccessor, fab));
42
43 // Install foo on the global object.
44 CHECK(env->Global()
45 ->Set(env.local(), v8_str("foo"),
46 foo->GetFunction(env.local()).ToLocalChecked())
47 .FromJust());
48
49 ExpectInt32("f = new foo(); f.bar", 123);
50 ExpectInt32("f = new foo(); f.barf", 123);
51 ExpectInt32("f = new foo(); f.barf", 123);
52 ExpectInt32("f = new foo(); f.barf", 123);
53 ExpectInt32("f = new foo(); f.barf", 124);
54 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698