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

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

Issue 1620293002: Add native callbacks to FastAccessorAssembler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: clean-up parameter handling 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/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 1e1c972694446cb304a69e82b35241ca3fac0704..9cadc28df1ff3be8475eb904f231fb4ebd23a359 100644
--- a/test/cctest/test-api-fast-accessor-builder.cc
+++ b/test/cctest/test-api-fast-accessor-builder.cc
@@ -51,9 +51,9 @@ namespace {
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"*/ " // 16 lines * 64 'X' =~ 1024 character comment.
-#define FN_WARMUP(name, src) \
- "function " name "() { " src INLINE_SPOILER \
- " }; for(i = 0; i < 2; i++) { " name "() } "
+#define FN(name, src) "function " name "() { " src INLINE_SPOILER " }"
+#define WARMUP(name, count) "for(i = 0; i < " count "; i++) { " name "() } "
+#define FN_WARMUP(name, src) FN(name, src) "; " WARMUP(name, "2")
static void NativePropertyAccessor(
const v8::FunctionCallbackInfo<v8::Value>& info) {
@@ -286,3 +286,67 @@ TEST(FastAccessorLoad) {
CompileRun(FN_WARMUP("loadval", "return obj.loadval"));
ExpectString("loadval()", "Hello");
}
+
+
+void ApiCallbackInt(const v8::FunctionCallbackInfo<v8::Value>& info) {
+ info.GetReturnValue().Set(12345);
+}
+
+const char* kApiCallbackStringValue =
+ "Hello World! Bizarro C++ world, actually.";
+void ApiCallbackString(const v8::FunctionCallbackInfo<v8::Value>& info) {
+ info.GetReturnValue().Set(v8_str(kApiCallbackStringValue));
+}
+
+
+void ApiCallbackParam(const v8::FunctionCallbackInfo<v8::Value>& info) {
+ CHECK_EQ(1, info.Length());
+ CHECK(info[0]->IsNumber());
+ info.GetReturnValue().Set(info[0]);
+}
+
+
+// "Fast" accessor, callback to embedder
+TEST(FastAccessorCallback) {
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
+
+ v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
+ {
+ auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
+ builder->ReturnValue(
+ builder->Call(&ApiCallbackInt, builder->IntegerConstant(999)));
+ foo->SetAccessorProperty(v8_str("int"),
+ v8::FunctionTemplate::NewWithFastHandler(
+ isolate, NativePropertyAccessor, builder));
+
+ builder = v8::experimental::FastAccessorBuilder::New(isolate);
+ builder->ReturnValue(
+ builder->Call(&ApiCallbackString, builder->IntegerConstant(0)));
+ foo->SetAccessorProperty(v8_str("str"),
+ v8::FunctionTemplate::NewWithFastHandler(
+ isolate, NativePropertyAccessor, builder));
+
+ builder = v8::experimental::FastAccessorBuilder::New(isolate);
+ builder->ReturnValue(
+ builder->Call(&ApiCallbackParam, builder->IntegerConstant(1000)));
+ foo->SetAccessorProperty(v8_str("param"),
+ 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());
+
+ // Callbacks:
+ CompileRun(FN_WARMUP("callbackint", "return obj.int"));
+ ExpectInt32("callbackint()", 12345);
+
+ CompileRun(FN_WARMUP("callbackstr", "return obj.str"));
+ ExpectString("callbackstr()", kApiCallbackStringValue);
+
+ CompileRun(FN_WARMUP("callbackparam", "return obj.param"));
+ ExpectInt32("callbackparam()", 1000);
+}
« no previous file with comments | « src/compiler/fast-accessor-assembler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698