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

Side by Side Diff: test/cctest/test-api-accessors.cc

Issue 1518703002: Re-re-land FastAccessorBuilder. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add test restrictions, as for test-api-fast-accessor-builder 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
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/test-api-fast-accessor-builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "test/cctest/cctest.h" 5 #include "test/cctest/cctest.h"
6 6
7 #include "include/v8.h" 7 #include "include/v8.h"
8 #include "src/compiler/pipeline.h" 8 #include "include/v8-experimental.h"
9 #include "src/compiler/raw-machine-assembler.h"
10 9
11 10
12 namespace i = v8::internal; 11 namespace i = v8::internal;
13 12
14 static void CppAccessor(const v8::FunctionCallbackInfo<v8::Value>& info) { 13 static void CppAccessor42(const v8::FunctionCallbackInfo<v8::Value>& info) {
15 info.GetReturnValue().Set(42); 14 info.GetReturnValue().Set(42);
16 } 15 }
17 16
18 17
19 v8::Local<v8::Value> RawAccessor(v8::Isolate* isolate) { 18 static void CppAccessor41(const v8::FunctionCallbackInfo<v8::Value>& info) {
20 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 19 info.GetReturnValue().Set(41);
21 i::Zone zone;
22 i::compiler::RawMachineAssembler raw_machine_assembler(
23 i_isolate, new (&zone) i::compiler::Graph(&zone),
24 i::compiler::Linkage::GetJSCallDescriptor(
25 &zone, false, 1, i::compiler::CallDescriptor::kNoFlags));
26 raw_machine_assembler.Return(raw_machine_assembler.NumberConstant(41));
27 i::CompilationInfo info("firstChildRaw", i_isolate, &zone);
28 i::compiler::Schedule* schedule = raw_machine_assembler.Export();
29 i::Handle<i::Code> code = i::compiler::Pipeline::GenerateCodeForTesting(
30 &info, raw_machine_assembler.call_descriptor(),
31 raw_machine_assembler.graph(), schedule);
32 return v8::Utils::ToLocal(i::Handle<i::Object>::cast(code));
33 } 20 }
34 21
35 22
36 TEST(JavascriptAccessors) { 23 v8::experimental::FastAccessorBuilder* FastAccessor(v8::Isolate* isolate) {
24 auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
25 builder->ReturnValue(builder->IntegerConstant(41));
26 return builder;
27 }
28
29
30 TEST(FastAccessors) {
31 if (i::FLAG_always_opt || i::FLAG_optimize_for_size) return;
32
37 v8::Isolate* isolate = CcTest::isolate(); 33 v8::Isolate* isolate = CcTest::isolate();
38 v8::HandleScope scope(isolate); 34 v8::HandleScope scope(isolate);
39 LocalContext env; 35 LocalContext env;
40 36
41 // We emulate Embedder-created DOM Node instances. Specifically: 37 // We emulate Embedder-created DOM Node instances. Specifically:
42 // - 'parent': FunctionTemplate ~= DOM Node superclass 38 // - 'parent': FunctionTemplate ~= DOM Node superclass
43 // - 'child': FunctionTemplate ~= a specific DOM node type, like a <div /> 39 // - 'child': FunctionTemplate ~= a specific DOM node type, like a <div />
44 // 40 //
45 // We'll install both a C++-based and a JS-based accessor on the parent, 41 // We'll install both a C++-based and a JS-based accessor on the parent,
46 // and expect it to be callable on the child. 42 // and expect it to be callable on the child.
47 43
48 // Setup the parent template ( =~ DOM Node w/ accessors). 44 // Setup the parent template ( =~ DOM Node w/ accessors).
49 v8::Local<v8::FunctionTemplate> parent = v8::FunctionTemplate::New(isolate); 45 v8::Local<v8::FunctionTemplate> parent = v8::FunctionTemplate::New(isolate);
50 { 46 {
51 auto signature = v8::Signature::New(isolate, parent); 47 auto signature = v8::Signature::New(isolate, parent);
52 48
53 // cpp accessor as "firstChild": 49 // cpp accessor as "firstChild":
54 parent->PrototypeTemplate()->SetAccessorProperty( 50 parent->PrototypeTemplate()->SetAccessorProperty(
55 v8_str("firstChild"), 51 v8_str("firstChild"),
56 v8::FunctionTemplate::New(isolate, CppAccessor, v8::Local<v8::Value>(), 52 v8::FunctionTemplate::New(isolate, CppAccessor42,
57 signature)); 53 v8::Local<v8::Value>(), signature));
58 54
59 // JS accessor as "firstChildRaw": 55 // JS accessor as "firstChildRaw":
60 auto raw_accessor = RawAccessor(isolate);
61 parent->PrototypeTemplate()->SetAccessorProperty( 56 parent->PrototypeTemplate()->SetAccessorProperty(
62 v8_str("firstChildRaw"), v8::FunctionTemplate::NewWithFastHandler( 57 v8_str("firstChildRaw"),
63 isolate, CppAccessor, raw_accessor, 58 v8::FunctionTemplate::NewWithFastHandler(
64 v8::Local<v8::Value>(), signature)); 59 isolate, CppAccessor41, FastAccessor(isolate),
60 v8::Local<v8::Value>(), signature));
65 } 61 }
66 62
67 // Setup child object ( =~ a specific DOM Node, e.g. a <div> ). 63 // Setup child object ( =~ a specific DOM Node, e.g. a <div> ).
68 // Also, make a creation function on the global object, so we can access it 64 // Also, make a creation function on the global object, so we can access it
69 // in a test. 65 // in a test.
70 v8::Local<v8::FunctionTemplate> child = v8::FunctionTemplate::New(isolate); 66 v8::Local<v8::FunctionTemplate> child = v8::FunctionTemplate::New(isolate);
71 child->Inherit(parent); 67 child->Inherit(parent);
72 CHECK(env->Global() 68 CHECK(env->Global()
73 ->Set(env.local(), v8_str("Node"), 69 ->Set(env.local(), v8_str("Node"),
74 child->GetFunction(env.local()).ToLocalChecked()) 70 child->GetFunction(env.local()).ToLocalChecked())
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 "var g = Object.getOwnPropertyDescriptor(" 106 "var g = Object.getOwnPropertyDescriptor("
111 " n.__proto__.__proto__, 'firstChildRaw')['get'];" 107 " n.__proto__.__proto__, 'firstChildRaw')['get'];"
112 "try {" 108 "try {"
113 " var f = { firstChildRaw: '51' };" 109 " var f = { firstChildRaw: '51' };"
114 " g.apply(f);" 110 " g.apply(f);"
115 "} catch(e) {" 111 "} catch(e) {"
116 " 31415;" 112 " 31415;"
117 "}", 113 "}",
118 31415); 114 31415);
119 } 115 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/test-api-fast-accessor-builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698