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

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

Issue 1580323003: Restrict GeneratePreagedPrologue to proper functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix CompilationCacheCachingBehavior for all combinations of --age-code and --optimize-for-size. Created 4 years, 11 months 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/test-api-accessors.cc ('k') | no next file » | 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 <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "include/v8.h" 7 #include "include/v8.h"
8 #include "include/v8-experimental.h" 8 #include "include/v8-experimental.h"
9 9
10 #include "src/api.h" 10 #include "src/api.h"
(...skipping 20 matching lines...) Expand all
31 static void NativePropertyAccessor( 31 static void NativePropertyAccessor(
32 const v8::FunctionCallbackInfo<v8::Value>& info) { 32 const v8::FunctionCallbackInfo<v8::Value>& info) {
33 info.GetReturnValue().Set(v8_num(123)); 33 info.GetReturnValue().Set(v8_num(123));
34 } 34 }
35 35
36 } // anonymous namespace 36 } // anonymous namespace
37 37
38 38
39 // Build a simple "fast accessor" and verify that it is being called. 39 // Build a simple "fast accessor" and verify that it is being called.
40 TEST(FastAccessor) { 40 TEST(FastAccessor) {
41 if (i::FLAG_always_opt || i::FLAG_optimize_for_size) return; 41 if (i::FLAG_always_opt) return;
42 42
43 LocalContext env; 43 LocalContext env;
44 v8::Isolate* isolate = env->GetIsolate(); 44 v8::Isolate* isolate = env->GetIsolate();
45 v8::HandleScope scope(isolate); 45 v8::HandleScope scope(isolate);
46 46
47 v8::Local<v8::FunctionTemplate> foo = v8::FunctionTemplate::New(isolate); 47 v8::Local<v8::FunctionTemplate> foo = v8::FunctionTemplate::New(isolate);
48 48
49 // Native accessor, bar, returns 123. 49 // Native accessor, bar, returns 123.
50 foo->PrototypeTemplate()->SetAccessorProperty( 50 foo->PrototypeTemplate()->SetAccessorProperty(
51 v8_str("bar"), 51 v8_str("bar"),
(...skipping 29 matching lines...) Expand all
81 builder->ReturnValue( 81 builder->ReturnValue(
82 builder->LoadInternalField(builder->GetReceiver(), field_no)); 82 builder->LoadInternalField(builder->GetReceiver(), field_no));
83 templ->SetAccessorProperty(v8_str(name), 83 templ->SetAccessorProperty(v8_str(name),
84 v8::FunctionTemplate::NewWithFastHandler( 84 v8::FunctionTemplate::NewWithFastHandler(
85 isolate, NativePropertyAccessor, builder)); 85 isolate, NativePropertyAccessor, builder));
86 } 86 }
87 87
88 88
89 // "Fast" accessor that accesses an internal field. 89 // "Fast" accessor that accesses an internal field.
90 TEST(FastAccessorWithInternalField) { 90 TEST(FastAccessorWithInternalField) {
91 if (i::FLAG_always_opt || i::FLAG_optimize_for_size) return; 91 if (i::FLAG_always_opt) return;
92 92
93 LocalContext env; 93 LocalContext env;
94 v8::Isolate* isolate = env->GetIsolate(); 94 v8::Isolate* isolate = env->GetIsolate();
95 v8::HandleScope scope(isolate); 95 v8::HandleScope scope(isolate);
96 96
97 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); 97 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
98 foo->SetInternalFieldCount(3); 98 foo->SetInternalFieldCount(3);
99 AddInternalFieldAccessor(isolate, foo, "field0", 0); 99 AddInternalFieldAccessor(isolate, foo, "field0", 0);
100 AddInternalFieldAccessor(isolate, foo, "field1", 1); 100 AddInternalFieldAccessor(isolate, foo, "field1", 1);
101 AddInternalFieldAccessor(isolate, foo, "field2", 2); 101 AddInternalFieldAccessor(isolate, foo, "field2", 2);
(...skipping 11 matching lines...) Expand all
113 113
114 // Access fields. 114 // Access fields.
115 ExpectString("field0()", "Hi there!"); 115 ExpectString("field0()", "Hi there!");
116 ExpectInt32("field1()", 4321); 116 ExpectInt32("field1()", 4321);
117 ExpectUndefined("field2()"); 117 ExpectUndefined("field2()");
118 } 118 }
119 119
120 120
121 // "Fast" accessor with control flow via ...OrReturnNull methods. 121 // "Fast" accessor with control flow via ...OrReturnNull methods.
122 TEST(FastAccessorOrReturnNull) { 122 TEST(FastAccessorOrReturnNull) {
123 if (i::FLAG_always_opt || i::FLAG_optimize_for_size) return; 123 if (i::FLAG_always_opt) return;
124 124
125 LocalContext env; 125 LocalContext env;
126 v8::Isolate* isolate = env->GetIsolate(); 126 v8::Isolate* isolate = env->GetIsolate();
127 v8::HandleScope scope(isolate); 127 v8::HandleScope scope(isolate);
128 128
129 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); 129 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
130 foo->SetInternalFieldCount(2); 130 foo->SetInternalFieldCount(2);
131 { 131 {
132 // accessor "nullcheck": Return null if field 0 is non-null object; else 5. 132 // accessor "nullcheck": Return null if field 0 is non-null object; else 5.
133 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); 133 auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 "function maskcheck() { return obj.maskcheck }; " WARMUP("maskcheck()")); 166 "function maskcheck() { return obj.maskcheck }; " WARMUP("maskcheck()"));
167 obj->SetAlignedPointerInInternalField(1, reinterpret_cast<void*>(0xf0)); 167 obj->SetAlignedPointerInInternalField(1, reinterpret_cast<void*>(0xf0));
168 ExpectInt32("maskcheck()", 42); 168 ExpectInt32("maskcheck()", 42);
169 obj->SetAlignedPointerInInternalField(1, reinterpret_cast<void*>(0xfe)); 169 obj->SetAlignedPointerInInternalField(1, reinterpret_cast<void*>(0xfe));
170 ExpectNull("maskcheck()"); 170 ExpectNull("maskcheck()");
171 } 171 }
172 172
173 173
174 // "Fast" accessor with simple control flow via explicit labels. 174 // "Fast" accessor with simple control flow via explicit labels.
175 TEST(FastAccessorControlFlowWithLabels) { 175 TEST(FastAccessorControlFlowWithLabels) {
176 if (i::FLAG_always_opt || i::FLAG_optimize_for_size) return; 176 if (i::FLAG_always_opt) return;
177 177
178 LocalContext env; 178 LocalContext env;
179 v8::Isolate* isolate = env->GetIsolate(); 179 v8::Isolate* isolate = env->GetIsolate();
180 v8::HandleScope scope(isolate); 180 v8::HandleScope scope(isolate);
181 181
182 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); 182 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
183 foo->SetInternalFieldCount(1); 183 foo->SetInternalFieldCount(1);
184 { 184 {
185 // accessor isnull: 0 for nullptr, else 1. 185 // accessor isnull: 0 for nullptr, else 1.
186 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); 186 auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
(...skipping 16 matching lines...) Expand all
203 CompileRun("function isnull() { return obj.isnull }; " WARMUP("isnull()")); 203 CompileRun("function isnull() { return obj.isnull }; " WARMUP("isnull()"));
204 obj->SetAlignedPointerInInternalField(0, /* anything != nullptr */ isolate); 204 obj->SetAlignedPointerInInternalField(0, /* anything != nullptr */ isolate);
205 ExpectInt32("isnull()", 1); 205 ExpectInt32("isnull()", 1);
206 obj->SetAlignedPointerInInternalField(0, nullptr); 206 obj->SetAlignedPointerInInternalField(0, nullptr);
207 ExpectInt32("isnull()", 0); 207 ExpectInt32("isnull()", 0);
208 } 208 }
209 209
210 210
211 // "Fast" accessor, loading things. 211 // "Fast" accessor, loading things.
212 TEST(FastAccessorLoad) { 212 TEST(FastAccessorLoad) {
213 if (i::FLAG_always_opt || i::FLAG_optimize_for_size) return; 213 if (i::FLAG_always_opt) return;
214 214
215 LocalContext env; 215 LocalContext env;
216 v8::Isolate* isolate = env->GetIsolate(); 216 v8::Isolate* isolate = env->GetIsolate();
217 v8::HandleScope scope(isolate); 217 v8::HandleScope scope(isolate);
218 218
219 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); 219 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
220 foo->SetInternalFieldCount(1); 220 foo->SetInternalFieldCount(1);
221 221
222 // Internal field 0 is a pointer to a C++ data structure that we wish to load 222 // Internal field 0 is a pointer to a C++ data structure that we wish to load
223 // field values from. 223 // field values from.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 ExpectInt32("nonzero()", 1); 265 ExpectInt32("nonzero()", 1);
266 val.intval = 0; 266 val.intval = 0;
267 ExpectInt32("nonzero()", 0); 267 ExpectInt32("nonzero()", 0);
268 val.intval = 27; 268 val.intval = 27;
269 ExpectInt32("nonzero()", 1); 269 ExpectInt32("nonzero()", 1);
270 270
271 // Access val.v8val: 271 // Access val.v8val:
272 CompileRun("function loadval() { return obj.loadval }; " WARMUP("loadval()")); 272 CompileRun("function loadval() { return obj.loadval }; " WARMUP("loadval()"));
273 ExpectString("loadval()", "Hello"); 273 ExpectString("loadval()", "Hello");
274 } 274 }
OLDNEW
« no previous file with comments | « test/cctest/test-api-accessors.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698