| OLD | NEW |
| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 .FromJust()); | 107 .FromJust()); |
| 108 | 108 |
| 109 // Wrap f.barf + IC warmup. | 109 // Wrap f.barf + IC warmup. |
| 110 CompileRun(FN_WARMUP("barf", "f = new foo(); return f.barf")); | 110 CompileRun(FN_WARMUP("barf", "f = new foo(); return f.barf")); |
| 111 | 111 |
| 112 ExpectInt32("f = new foo(); f.bar", 123); | 112 ExpectInt32("f = new foo(); f.bar", 123); |
| 113 ExpectInt32("f = new foo(); f.barf", 123); // First call in this call site. | 113 ExpectInt32("f = new foo(); f.barf", 123); // First call in this call site. |
| 114 ExpectInt32("barf()", 124); // Call via warmed-up callsite. | 114 ExpectInt32("barf()", 124); // Call via warmed-up callsite. |
| 115 } | 115 } |
| 116 | 116 |
| 117 void AddInternalFieldAccessor(v8::Isolate* isolate, | 117 void AddEmbedderFieldAccessor(v8::Isolate* isolate, |
| 118 v8::Local<v8::Template> templ, const char* name, | 118 v8::Local<v8::Template> templ, const char* name, |
| 119 int field_no, bool useUncheckedLoader) { | 119 int field_no, bool useUncheckedLoader) { |
| 120 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); | 120 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); |
| 121 | 121 |
| 122 if (useUncheckedLoader) { | 122 if (useUncheckedLoader) { |
| 123 builder->ReturnValue( | 123 builder->ReturnValue( |
| 124 builder->LoadInternalFieldUnchecked(builder->GetReceiver(), field_no)); | 124 builder->LoadEmbedderFieldUnchecked(builder->GetReceiver(), field_no)); |
| 125 } else { | 125 } else { |
| 126 builder->ReturnValue( | 126 builder->ReturnValue( |
| 127 builder->LoadInternalField(builder->GetReceiver(), field_no)); | 127 builder->LoadEmbedderField(builder->GetReceiver(), field_no)); |
| 128 } | 128 } |
| 129 | 129 |
| 130 templ->SetAccessorProperty(v8_str(name), | 130 templ->SetAccessorProperty(v8_str(name), |
| 131 v8::FunctionTemplate::NewWithFastHandler( | 131 v8::FunctionTemplate::NewWithFastHandler( |
| 132 isolate, NativePropertyAccessor, builder)); | 132 isolate, NativePropertyAccessor, builder)); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void checkLoadInternalField(bool useUncheckedLoader, bool emitDebugChecks) { | 135 void checkLoadEmbedderField(bool useUncheckedLoader, bool emitDebugChecks) { |
| 136 // Crankshaft support for fast accessors is not implemented; crankshafted | 136 // Crankshaft support for fast accessors is not implemented; crankshafted |
| 137 // code uses the slow accessor which breaks this test's expectations. | 137 // code uses the slow accessor which breaks this test's expectations. |
| 138 v8::internal::FLAG_always_opt = false; | 138 v8::internal::FLAG_always_opt = false; |
| 139 | 139 |
| 140 // De/activate debug checks. | 140 // De/activate debug checks. |
| 141 v8::internal::FLAG_debug_code = emitDebugChecks; | 141 v8::internal::FLAG_debug_code = emitDebugChecks; |
| 142 LocalContext env; | 142 LocalContext env; |
| 143 v8::Isolate* isolate = env->GetIsolate(); | 143 v8::Isolate* isolate = env->GetIsolate(); |
| 144 v8::HandleScope scope(isolate); | 144 v8::HandleScope scope(isolate); |
| 145 | 145 |
| 146 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); | 146 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); |
| 147 foo->SetInternalFieldCount(3); | 147 foo->SetEmbedderFieldCount(3); |
| 148 AddInternalFieldAccessor(isolate, foo, "field0", 0, useUncheckedLoader); | 148 AddEmbedderFieldAccessor(isolate, foo, "field0", 0, useUncheckedLoader); |
| 149 AddInternalFieldAccessor(isolate, foo, "field1", 1, useUncheckedLoader); | 149 AddEmbedderFieldAccessor(isolate, foo, "field1", 1, useUncheckedLoader); |
| 150 AddInternalFieldAccessor(isolate, foo, "field2", 2, useUncheckedLoader); | 150 AddEmbedderFieldAccessor(isolate, foo, "field2", 2, useUncheckedLoader); |
| 151 | 151 |
| 152 // Create an instance w/ 3 internal fields, put in a string, a Smi, nothing. | 152 // Create an instance w/ 3 embedder fields, put in a string, a Smi, nothing. |
| 153 v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); | 153 v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); |
| 154 obj->SetInternalField(0, v8_str("Hi there!")); | 154 obj->SetEmbedderField(0, v8_str("Hi there!")); |
| 155 obj->SetInternalField(1, v8::Integer::New(isolate, 4321)); | 155 obj->SetEmbedderField(1, v8::Integer::New(isolate, 4321)); |
| 156 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); | 156 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); |
| 157 | 157 |
| 158 // Warmup. | 158 // Warmup. |
| 159 CompileRun(FN_WARMUP("field0", "return obj.field0")); | 159 CompileRun(FN_WARMUP("field0", "return obj.field0")); |
| 160 CompileRun(FN_WARMUP("field1", "return obj.field1")); | 160 CompileRun(FN_WARMUP("field1", "return obj.field1")); |
| 161 CompileRun(FN_WARMUP("field2", "return obj.field2")); | 161 CompileRun(FN_WARMUP("field2", "return obj.field2")); |
| 162 | 162 |
| 163 // Access fields. | 163 // Access fields. |
| 164 ExpectString("field0()", "Hi there!"); | 164 ExpectString("field0()", "Hi there!"); |
| 165 ExpectInt32("field1()", 4321); | 165 ExpectInt32("field1()", 4321); |
| 166 ExpectUndefined("field2()"); | 166 ExpectUndefined("field2()"); |
| 167 } | 167 } |
| 168 | 168 |
| 169 // "Fast" accessor that accesses an internal field. | 169 // "Fast" accessor that accesses an embedder field. |
| 170 TEST(FastAccessorWithInternalField) { checkLoadInternalField(false, false); } | 170 TEST(FastAccessorWithEmbedderField) { checkLoadEmbedderField(false, false); } |
| 171 | 171 |
| 172 // "Fast" accessor that accesses an internal field using the fast(er) | 172 // "Fast" accessor that accesses an embedder field using the fast(er) |
| 173 // implementation of LoadInternalField. | 173 // implementation of LoadEmbedderField. |
| 174 TEST(FastAccessorLoadInternalFieldUnchecked) { | 174 TEST(FastAccessorLoadEmbedderFieldUnchecked) { |
| 175 checkLoadInternalField(true, false); | 175 checkLoadEmbedderField(true, false); |
| 176 checkLoadInternalField(true, true); | 176 checkLoadEmbedderField(true, true); |
| 177 } | 177 } |
| 178 | 178 |
| 179 // "Fast" accessor with control flow via ...OrReturnNull methods. | 179 // "Fast" accessor with control flow via ...OrReturnNull methods. |
| 180 TEST(FastAccessorOrReturnNull) { | 180 TEST(FastAccessorOrReturnNull) { |
| 181 // Crankshaft support for fast accessors is not implemented; crankshafted | 181 // Crankshaft support for fast accessors is not implemented; crankshafted |
| 182 // code uses the slow accessor which breaks this test's expectations. | 182 // code uses the slow accessor which breaks this test's expectations. |
| 183 v8::internal::FLAG_always_opt = false; | 183 v8::internal::FLAG_always_opt = false; |
| 184 LocalContext env; | 184 LocalContext env; |
| 185 v8::Isolate* isolate = env->GetIsolate(); | 185 v8::Isolate* isolate = env->GetIsolate(); |
| 186 v8::HandleScope scope(isolate); | 186 v8::HandleScope scope(isolate); |
| 187 | 187 |
| 188 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); | 188 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); |
| 189 foo->SetInternalFieldCount(2); | 189 foo->SetEmbedderFieldCount(2); |
| 190 { | 190 { |
| 191 // accessor "nullcheck": Return null if field 0 is non-null object; else 5. | 191 // accessor "nullcheck": Return null if field 0 is non-null object; else 5. |
| 192 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); | 192 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); |
| 193 auto val = builder->LoadInternalField(builder->GetReceiver(), 0); | 193 auto val = builder->LoadEmbedderField(builder->GetReceiver(), 0); |
| 194 builder->CheckNotZeroOrReturnNull(val); | 194 builder->CheckNotZeroOrReturnNull(val); |
| 195 builder->ReturnValue(builder->IntegerConstant(5)); | 195 builder->ReturnValue(builder->IntegerConstant(5)); |
| 196 foo->SetAccessorProperty(v8_str("nullcheck"), | 196 foo->SetAccessorProperty(v8_str("nullcheck"), |
| 197 v8::FunctionTemplate::NewWithFastHandler( | 197 v8::FunctionTemplate::NewWithFastHandler( |
| 198 isolate, NativePropertyAccessor, builder)); | 198 isolate, NativePropertyAccessor, builder)); |
| 199 } | 199 } |
| 200 { | 200 { |
| 201 // accessor "maskcheck": Return null if field 1 has 3rd bit set. | 201 // accessor "maskcheck": Return null if field 1 has 3rd bit set. |
| 202 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); | 202 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); |
| 203 auto val = builder->LoadInternalField(builder->GetReceiver(), 1); | 203 auto val = builder->LoadEmbedderField(builder->GetReceiver(), 1); |
| 204 builder->CheckFlagSetOrReturnNull(val, 0x4); | 204 builder->CheckFlagSetOrReturnNull(val, 0x4); |
| 205 builder->ReturnValue(builder->IntegerConstant(42)); | 205 builder->ReturnValue(builder->IntegerConstant(42)); |
| 206 foo->SetAccessorProperty(v8_str("maskcheck"), | 206 foo->SetAccessorProperty(v8_str("maskcheck"), |
| 207 v8::FunctionTemplate::NewWithFastHandler( | 207 v8::FunctionTemplate::NewWithFastHandler( |
| 208 isolate, NativePropertyAccessor, builder)); | 208 isolate, NativePropertyAccessor, builder)); |
| 209 } | 209 } |
| 210 | 210 |
| 211 // Create an instance. | 211 // Create an instance. |
| 212 v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); | 212 v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); |
| 213 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); | 213 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); |
| 214 | 214 |
| 215 // CheckNotZeroOrReturnNull: | 215 // CheckNotZeroOrReturnNull: |
| 216 CompileRun(FN_WARMUP("nullcheck", "return obj.nullcheck")); | 216 CompileRun(FN_WARMUP("nullcheck", "return obj.nullcheck")); |
| 217 obj->SetAlignedPointerInInternalField(0, /* anything != nullptr */ isolate); | 217 obj->SetAlignedPointerInEmbedderField(0, /* anything != nullptr */ isolate); |
| 218 ExpectInt32("nullcheck()", 5); | 218 ExpectInt32("nullcheck()", 5); |
| 219 obj->SetAlignedPointerInInternalField(0, nullptr); | 219 obj->SetAlignedPointerInEmbedderField(0, nullptr); |
| 220 ExpectNull("nullcheck()"); | 220 ExpectNull("nullcheck()"); |
| 221 | 221 |
| 222 // CheckFlagSetOrReturnNull: | 222 // CheckFlagSetOrReturnNull: |
| 223 CompileRun(FN_WARMUP("maskcheck", "return obj.maskcheck")); | 223 CompileRun(FN_WARMUP("maskcheck", "return obj.maskcheck")); |
| 224 obj->SetAlignedPointerInInternalField(1, reinterpret_cast<void*>(0xf0)); | 224 obj->SetAlignedPointerInEmbedderField(1, reinterpret_cast<void*>(0xf0)); |
| 225 ExpectNull("maskcheck()"); | 225 ExpectNull("maskcheck()"); |
| 226 obj->SetAlignedPointerInInternalField(1, reinterpret_cast<void*>(0xfe)); | 226 obj->SetAlignedPointerInEmbedderField(1, reinterpret_cast<void*>(0xfe)); |
| 227 ExpectInt32("maskcheck()", 42); | 227 ExpectInt32("maskcheck()", 42); |
| 228 } | 228 } |
| 229 | 229 |
| 230 | 230 |
| 231 // "Fast" accessor with simple control flow via explicit labels. | 231 // "Fast" accessor with simple control flow via explicit labels. |
| 232 TEST(FastAccessorControlFlowWithLabels) { | 232 TEST(FastAccessorControlFlowWithLabels) { |
| 233 // Crankshaft support for fast accessors is not implemented; crankshafted | 233 // Crankshaft support for fast accessors is not implemented; crankshafted |
| 234 // code uses the slow accessor which breaks this test's expectations. | 234 // code uses the slow accessor which breaks this test's expectations. |
| 235 v8::internal::FLAG_always_opt = false; | 235 v8::internal::FLAG_always_opt = false; |
| 236 LocalContext env; | 236 LocalContext env; |
| 237 v8::Isolate* isolate = env->GetIsolate(); | 237 v8::Isolate* isolate = env->GetIsolate(); |
| 238 v8::HandleScope scope(isolate); | 238 v8::HandleScope scope(isolate); |
| 239 | 239 |
| 240 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); | 240 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); |
| 241 foo->SetInternalFieldCount(1); | 241 foo->SetEmbedderFieldCount(1); |
| 242 { | 242 { |
| 243 // accessor isnull: 0 for nullptr, else 1. | 243 // accessor isnull: 0 for nullptr, else 1. |
| 244 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); | 244 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); |
| 245 auto label = builder->MakeLabel(); | 245 auto label = builder->MakeLabel(); |
| 246 auto val = builder->LoadInternalField(builder->GetReceiver(), 0); | 246 auto val = builder->LoadEmbedderField(builder->GetReceiver(), 0); |
| 247 builder->CheckNotZeroOrJump(val, label); | 247 builder->CheckNotZeroOrJump(val, label); |
| 248 builder->ReturnValue(builder->IntegerConstant(1)); | 248 builder->ReturnValue(builder->IntegerConstant(1)); |
| 249 builder->SetLabel(label); | 249 builder->SetLabel(label); |
| 250 builder->ReturnValue(builder->IntegerConstant(0)); | 250 builder->ReturnValue(builder->IntegerConstant(0)); |
| 251 foo->SetAccessorProperty(v8_str("isnull"), | 251 foo->SetAccessorProperty(v8_str("isnull"), |
| 252 v8::FunctionTemplate::NewWithFastHandler( | 252 v8::FunctionTemplate::NewWithFastHandler( |
| 253 isolate, NativePropertyAccessor, builder)); | 253 isolate, NativePropertyAccessor, builder)); |
| 254 } | 254 } |
| 255 | 255 |
| 256 // Create an instance. | 256 // Create an instance. |
| 257 v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); | 257 v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); |
| 258 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); | 258 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); |
| 259 | 259 |
| 260 // CheckNotZeroOrReturnNull: | 260 // CheckNotZeroOrReturnNull: |
| 261 CompileRun(FN_WARMUP("isnull", "return obj.isnull")); | 261 CompileRun(FN_WARMUP("isnull", "return obj.isnull")); |
| 262 obj->SetAlignedPointerInInternalField(0, /* anything != nullptr */ isolate); | 262 obj->SetAlignedPointerInEmbedderField(0, /* anything != nullptr */ isolate); |
| 263 ExpectInt32("isnull()", 1); | 263 ExpectInt32("isnull()", 1); |
| 264 obj->SetAlignedPointerInInternalField(0, nullptr); | 264 obj->SetAlignedPointerInEmbedderField(0, nullptr); |
| 265 ExpectInt32("isnull()", 0); | 265 ExpectInt32("isnull()", 0); |
| 266 } | 266 } |
| 267 | 267 |
| 268 | 268 |
| 269 // "Fast" accessor, loading things. | 269 // "Fast" accessor, loading things. |
| 270 TEST(FastAccessorLoad) { | 270 TEST(FastAccessorLoad) { |
| 271 // Crankshaft support for fast accessors is not implemented; crankshafted | 271 // Crankshaft support for fast accessors is not implemented; crankshafted |
| 272 // code uses the slow accessor which breaks this test's expectations. | 272 // code uses the slow accessor which breaks this test's expectations. |
| 273 v8::internal::FLAG_always_opt = false; | 273 v8::internal::FLAG_always_opt = false; |
| 274 LocalContext env; | 274 LocalContext env; |
| 275 v8::Isolate* isolate = env->GetIsolate(); | 275 v8::Isolate* isolate = env->GetIsolate(); |
| 276 v8::HandleScope scope(isolate); | 276 v8::HandleScope scope(isolate); |
| 277 | 277 |
| 278 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); | 278 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); |
| 279 foo->SetInternalFieldCount(1); | 279 foo->SetEmbedderFieldCount(1); |
| 280 | 280 |
| 281 // Internal field 0 is a pointer to a C++ data structure that we wish to load | 281 // Internal field 0 is a pointer to a C++ data structure that we wish to load |
| 282 // field values from. | 282 // field values from. |
| 283 struct { | 283 struct { |
| 284 size_t intval; | 284 size_t intval; |
| 285 v8::Local<v8::String> v8val; | 285 v8::Local<v8::String> v8val; |
| 286 } val = {54321, v8_str("Hello")}; | 286 } val = {54321, v8_str("Hello")}; |
| 287 | 287 |
| 288 { | 288 { |
| 289 // accessor intisnonzero | 289 // accessor intisnonzero |
| 290 int intval_offset = | 290 int intval_offset = |
| 291 static_cast<int>(reinterpret_cast<intptr_t>(&val.intval) - | 291 static_cast<int>(reinterpret_cast<intptr_t>(&val.intval) - |
| 292 reinterpret_cast<intptr_t>(&val)); | 292 reinterpret_cast<intptr_t>(&val)); |
| 293 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); | 293 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); |
| 294 auto label = builder->MakeLabel(); | 294 auto label = builder->MakeLabel(); |
| 295 auto val = builder->LoadValue( | 295 auto val = builder->LoadValue( |
| 296 builder->LoadInternalField(builder->GetReceiver(), 0), intval_offset); | 296 builder->LoadEmbedderField(builder->GetReceiver(), 0), intval_offset); |
| 297 builder->CheckNotZeroOrJump(val, label); | 297 builder->CheckNotZeroOrJump(val, label); |
| 298 builder->ReturnValue(builder->IntegerConstant(1)); | 298 builder->ReturnValue(builder->IntegerConstant(1)); |
| 299 builder->SetLabel(label); | 299 builder->SetLabel(label); |
| 300 builder->ReturnValue(builder->IntegerConstant(0)); | 300 builder->ReturnValue(builder->IntegerConstant(0)); |
| 301 foo->SetAccessorProperty(v8_str("nonzero"), | 301 foo->SetAccessorProperty(v8_str("nonzero"), |
| 302 v8::FunctionTemplate::NewWithFastHandler( | 302 v8::FunctionTemplate::NewWithFastHandler( |
| 303 isolate, NativePropertyAccessor, builder)); | 303 isolate, NativePropertyAccessor, builder)); |
| 304 } | 304 } |
| 305 { | 305 { |
| 306 // accessor loadval | 306 // accessor loadval |
| 307 int v8val_offset = static_cast<int>(reinterpret_cast<intptr_t>(&val.v8val) - | 307 int v8val_offset = static_cast<int>(reinterpret_cast<intptr_t>(&val.v8val) - |
| 308 reinterpret_cast<intptr_t>(&val)); | 308 reinterpret_cast<intptr_t>(&val)); |
| 309 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); | 309 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); |
| 310 builder->ReturnValue(builder->LoadObject( | 310 builder->ReturnValue(builder->LoadObject( |
| 311 builder->LoadInternalField(builder->GetReceiver(), 0), v8val_offset)); | 311 builder->LoadEmbedderField(builder->GetReceiver(), 0), v8val_offset)); |
| 312 foo->SetAccessorProperty(v8_str("loadval"), | 312 foo->SetAccessorProperty(v8_str("loadval"), |
| 313 v8::FunctionTemplate::NewWithFastHandler( | 313 v8::FunctionTemplate::NewWithFastHandler( |
| 314 isolate, NativePropertyAccessor, builder)); | 314 isolate, NativePropertyAccessor, builder)); |
| 315 } | 315 } |
| 316 | 316 |
| 317 // Create an instance. | 317 // Create an instance. |
| 318 v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); | 318 v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); |
| 319 obj->SetAlignedPointerInInternalField(0, &val); | 319 obj->SetAlignedPointerInEmbedderField(0, &val); |
| 320 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); | 320 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); |
| 321 | 321 |
| 322 // Access val.intval: | 322 // Access val.intval: |
| 323 CompileRun(FN_WARMUP("nonzero", "return obj.nonzero")); | 323 CompileRun(FN_WARMUP("nonzero", "return obj.nonzero")); |
| 324 ExpectInt32("nonzero()", 1); | 324 ExpectInt32("nonzero()", 1); |
| 325 val.intval = 0; | 325 val.intval = 0; |
| 326 ExpectInt32("nonzero()", 0); | 326 ExpectInt32("nonzero()", 0); |
| 327 val.intval = 27; | 327 val.intval = 27; |
| 328 ExpectInt32("nonzero()", 1); | 328 ExpectInt32("nonzero()", 1); |
| 329 | 329 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 | 404 |
| 405 TEST(FastAccessorToSmi) { | 405 TEST(FastAccessorToSmi) { |
| 406 // Crankshaft support for fast accessors is not implemented; crankshafted | 406 // Crankshaft support for fast accessors is not implemented; crankshafted |
| 407 // code uses the slow accessor which breaks this test's expectations. | 407 // code uses the slow accessor which breaks this test's expectations. |
| 408 v8::internal::FLAG_always_opt = false; | 408 v8::internal::FLAG_always_opt = false; |
| 409 LocalContext env; | 409 LocalContext env; |
| 410 v8::Isolate* isolate = env->GetIsolate(); | 410 v8::Isolate* isolate = env->GetIsolate(); |
| 411 v8::HandleScope scope(isolate); | 411 v8::HandleScope scope(isolate); |
| 412 | 412 |
| 413 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); | 413 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); |
| 414 foo->SetInternalFieldCount(1); | 414 foo->SetEmbedderFieldCount(1); |
| 415 | 415 |
| 416 { | 416 { |
| 417 // Accessor load_smi. | 417 // Accessor load_smi. |
| 418 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); | 418 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); |
| 419 | 419 |
| 420 // Read the variable and convert it to a Smi. | 420 // Read the variable and convert it to a Smi. |
| 421 auto flags = builder->LoadValue( | 421 auto flags = builder->LoadValue( |
| 422 builder->LoadInternalField(builder->GetReceiver(), 0), 0); | 422 builder->LoadEmbedderField(builder->GetReceiver(), 0), 0); |
| 423 builder->ReturnValue(builder->ToSmi(flags)); | 423 builder->ReturnValue(builder->ToSmi(flags)); |
| 424 foo->SetAccessorProperty(v8_str("load_smi"), | 424 foo->SetAccessorProperty(v8_str("load_smi"), |
| 425 v8::FunctionTemplate::NewWithFastHandler( | 425 v8::FunctionTemplate::NewWithFastHandler( |
| 426 isolate, NativePropertyAccessor, builder)); | 426 isolate, NativePropertyAccessor, builder)); |
| 427 } | 427 } |
| 428 | 428 |
| 429 // Create an instance. | 429 // Create an instance. |
| 430 v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); | 430 v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); |
| 431 | 431 |
| 432 uintptr_t flags; | 432 uintptr_t flags; |
| 433 obj->SetAlignedPointerInInternalField(0, &flags); | 433 obj->SetAlignedPointerInEmbedderField(0, &flags); |
| 434 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); | 434 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); |
| 435 | 435 |
| 436 // Access flags. | 436 // Access flags. |
| 437 CompileRun(FN_WARMUP("load_smi", "return obj.load_smi")); | 437 CompileRun(FN_WARMUP("load_smi", "return obj.load_smi")); |
| 438 | 438 |
| 439 flags = 54321; | 439 flags = 54321; |
| 440 ExpectInt32("load_smi()", 54321); | 440 ExpectInt32("load_smi()", 54321); |
| 441 | 441 |
| 442 flags = 0; | 442 flags = 0; |
| 443 ExpectInt32("load_smi()", 0); | 443 ExpectInt32("load_smi()", 0); |
| 444 | 444 |
| 445 flags = 123456789; | 445 flags = 123456789; |
| 446 ExpectInt32("load_smi()", 123456789); | 446 ExpectInt32("load_smi()", 123456789); |
| 447 } | 447 } |
| 448 | 448 |
| 449 TEST(FastAccessorGoto) { | 449 TEST(FastAccessorGoto) { |
| 450 // Crankshaft support for fast accessors is not implemented; crankshafted | 450 // Crankshaft support for fast accessors is not implemented; crankshafted |
| 451 // code uses the slow accessor which breaks this test's expectations. | 451 // code uses the slow accessor which breaks this test's expectations. |
| 452 v8::internal::FLAG_always_opt = false; | 452 v8::internal::FLAG_always_opt = false; |
| 453 LocalContext env; | 453 LocalContext env; |
| 454 v8::Isolate* isolate = env->GetIsolate(); | 454 v8::Isolate* isolate = env->GetIsolate(); |
| 455 v8::HandleScope scope(isolate); | 455 v8::HandleScope scope(isolate); |
| 456 | 456 |
| 457 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); | 457 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); |
| 458 foo->SetInternalFieldCount(1); | 458 foo->SetEmbedderFieldCount(1); |
| 459 | 459 |
| 460 { | 460 { |
| 461 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); | 461 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); |
| 462 auto successLabel = builder->MakeLabel(); | 462 auto successLabel = builder->MakeLabel(); |
| 463 auto failLabel = builder->MakeLabel(); | 463 auto failLabel = builder->MakeLabel(); |
| 464 | 464 |
| 465 // The underlying raw assembler is clever enough to reject unreachable | 465 // The underlying raw assembler is clever enough to reject unreachable |
| 466 // basic blocks, this instruction has no effect besides marking the failed | 466 // basic blocks, this instruction has no effect besides marking the failed |
| 467 // return BB as reachable. | 467 // return BB as reachable. |
| 468 builder->CheckNotZeroOrJump(builder->IntegerConstant(1234), failLabel); | 468 builder->CheckNotZeroOrJump(builder->IntegerConstant(1234), failLabel); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 483 // Create an instance. | 483 // Create an instance. |
| 484 v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); | 484 v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked(); |
| 485 | 485 |
| 486 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); | 486 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); |
| 487 | 487 |
| 488 // Access flags. | 488 // Access flags. |
| 489 CompileRun(FN_WARMUP("test", "return obj.goto_test")); | 489 CompileRun(FN_WARMUP("test", "return obj.goto_test")); |
| 490 | 490 |
| 491 ExpectInt32("test()", 60707357); | 491 ExpectInt32("test()", 60707357); |
| 492 } | 492 } |
| OLD | NEW |