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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/fast-accessor-assembler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api-fast-accessor-builder.cc
diff --git a/test/cctest/test-api-fast-accessor-builder.cc b/test/cctest/test-api-fast-accessor-builder.cc
index 7ae089bf69cf3b52669f898f245d4c46b9a0c419..9dde2c7df856e5b0ee51b98a2be02e0b8df389e6 100644
--- a/test/cctest/test-api-fast-accessor-builder.cc
+++ b/test/cctest/test-api-fast-accessor-builder.cc
@@ -400,3 +400,92 @@ TEST(FastAccessorCallback) {
CompileRun(FN_WARMUP("callbackparam", "return obj.param"));
ExpectInt32("callbackparam()", 1000);
}
+
+TEST(FastAccessorToSmi) {
+ // Crankshaft support for fast accessors is not implemented; crankshafted
+ // code uses the slow accessor which breaks this test's expectations.
+ v8::internal::FLAG_always_opt = false;
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
+
+ v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
+ foo->SetInternalFieldCount(1);
+
+ {
+ // Accessor load_smi.
+ auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
+
+ // Read the variable and convert it to a Smi.
+ auto flags = builder->LoadValue(
+ builder->LoadInternalField(builder->GetReceiver(), 0), 0);
+ builder->ReturnValue(builder->ToSmi(flags));
+ foo->SetAccessorProperty(v8_str("load_smi"),
+ v8::FunctionTemplate::NewWithFastHandler(
+ isolate, NativePropertyAccessor, builder));
+ }
+
+ // Create an instance.
+ v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked();
+
+ uint32_t flags;
+ obj->SetAlignedPointerInInternalField(0, &flags);
+ CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
+
+ // Access flags.
+ CompileRun(FN_WARMUP("load_smi", "return obj.load_smi"));
+
+ flags = 54321;
+ ExpectInt32("load_smi()", 54321);
+
+ flags = 0;
+ ExpectInt32("load_smi()", 0);
+
+ flags = 123456789;
+ ExpectInt32("load_smi()", 123456789);
+}
+
+TEST(FastAccessorGoto) {
+ // Crankshaft support for fast accessors is not implemented; crankshafted
+ // code uses the slow accessor which breaks this test's expectations.
+ v8::internal::FLAG_always_opt = false;
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
+
+ v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
+ foo->SetInternalFieldCount(1);
+
+ {
+ auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
+ auto successLabel = builder->MakeLabel();
+ auto failLabel = builder->MakeLabel();
+
+ // The underlying raw assembler is clever enough to reject unreachable
+ // basic blocks, this instruction has no effect besides marking the failed
+ // return BB as reachable.
+ builder->CheckNotZeroOrJump(builder->IntegerConstant(1234), failLabel);
+
+ builder->Goto(successLabel);
+
+ builder->SetLabel(failLabel);
+ builder->ReturnValue(builder->IntegerConstant(0));
+
+ builder->SetLabel(successLabel);
+ builder->ReturnValue(builder->IntegerConstant(60707357));
+
+ foo->SetAccessorProperty(v8_str("goto_test"),
+ v8::FunctionTemplate::NewWithFastHandler(
+ isolate, NativePropertyAccessor, builder));
+ }
+
+ // Create an instance.
+ v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked();
+
+ CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
+
+ // Access flags.
+ CompileRun(FN_WARMUP("test", "return obj.goto_test"));
+
+ ExpectInt32("test()", 60707357);
+}
« 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