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

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

Issue 2237443002: Add ToSmi and Goto operations to FastAccessorAssembler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix 32-bit SMI overflow in test Created 4 years, 4 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 | « src/fast-accessor-assembler.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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 // Callbacks: 393 // Callbacks:
394 CompileRun(FN_WARMUP("callbackint", "return obj.int")); 394 CompileRun(FN_WARMUP("callbackint", "return obj.int"));
395 ExpectInt32("callbackint()", 12345); 395 ExpectInt32("callbackint()", 12345);
396 396
397 CompileRun(FN_WARMUP("callbackstr", "return obj.str")); 397 CompileRun(FN_WARMUP("callbackstr", "return obj.str"));
398 ExpectString("callbackstr()", kApiCallbackStringValue); 398 ExpectString("callbackstr()", kApiCallbackStringValue);
399 399
400 CompileRun(FN_WARMUP("callbackparam", "return obj.param")); 400 CompileRun(FN_WARMUP("callbackparam", "return obj.param"));
401 ExpectInt32("callbackparam()", 1000); 401 ExpectInt32("callbackparam()", 1000);
402 } 402 }
403
404 TEST(FastAccessorToSmi) {
405 // Crankshaft support for fast accessors is not implemented; crankshafted
406 // code uses the slow accessor which breaks this test's expectations.
407 v8::internal::FLAG_always_opt = false;
408 LocalContext env;
409 v8::Isolate* isolate = env->GetIsolate();
410 v8::HandleScope scope(isolate);
411
412 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
413 foo->SetInternalFieldCount(1);
414
415 {
416 // Accessor load_smi.
417 auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
418
419 // Read the variable and convert it to a Smi.
420 auto flags = builder->LoadValue(
421 builder->LoadInternalField(builder->GetReceiver(), 0), 0);
422 builder->ReturnValue(builder->ToSmi(flags));
423 foo->SetAccessorProperty(v8_str("load_smi"),
424 v8::FunctionTemplate::NewWithFastHandler(
425 isolate, NativePropertyAccessor, builder));
426 }
427
428 // Create an instance.
429 v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked();
430
431 uint32_t flags;
432 obj->SetAlignedPointerInInternalField(0, &flags);
433 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
434
435 // Access flags.
436 CompileRun(FN_WARMUP("load_smi", "return obj.load_smi"));
437
438 flags = 54321;
439 ExpectInt32("load_smi()", 54321);
440
441 flags = 0;
442 ExpectInt32("load_smi()", 0);
443
444 flags = 123456789;
445 ExpectInt32("load_smi()", 123456789);
446 }
447
448 TEST(FastAccessorGoto) {
449 // Crankshaft support for fast accessors is not implemented; crankshafted
450 // code uses the slow accessor which breaks this test's expectations.
451 v8::internal::FLAG_always_opt = false;
452 LocalContext env;
453 v8::Isolate* isolate = env->GetIsolate();
454 v8::HandleScope scope(isolate);
455
456 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
457 foo->SetInternalFieldCount(1);
458
459 {
460 auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
461 auto successLabel = builder->MakeLabel();
462 auto failLabel = builder->MakeLabel();
463
464 // The underlying raw assembler is clever enough to reject unreachable
465 // basic blocks, this instruction has no effect besides marking the failed
466 // return BB as reachable.
467 builder->CheckNotZeroOrJump(builder->IntegerConstant(1234), failLabel);
468
469 builder->Goto(successLabel);
470
471 builder->SetLabel(failLabel);
472 builder->ReturnValue(builder->IntegerConstant(0));
473
474 builder->SetLabel(successLabel);
475 builder->ReturnValue(builder->IntegerConstant(60707357));
476
477 foo->SetAccessorProperty(v8_str("goto_test"),
478 v8::FunctionTemplate::NewWithFastHandler(
479 isolate, NativePropertyAccessor, builder));
480 }
481
482 // Create an instance.
483 v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked();
484
485 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
486
487 // Access flags.
488 CompileRun(FN_WARMUP("test", "return obj.goto_test"));
489
490 ExpectInt32("test()", 60707357);
491 }
OLDNEW
« no previous file with comments | « src/fast-accessor-assembler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698