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

Unified Diff: src/runtime/runtime-test.cc

Issue 2208703002: [wasm] Allow import function to be any kind of callables. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase. 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/runtime/runtime.h ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-test.cc
diff --git a/src/runtime/runtime-test.cc b/src/runtime/runtime-test.cc
index 1f1e0f4b4663b9bbc0b7318f47d095fba0030b69..36d359712e541066ca24dd8c81cece0be4121909 100644
--- a/src/runtime/runtime-test.cc
+++ b/src/runtime/runtime-test.cc
@@ -261,6 +261,34 @@ RUNTIME_FUNCTION(Runtime_GetUndetectable) {
return *Utils::OpenHandle(*obj);
}
+static void call_as_function(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ double v1 = args[0]
+ ->NumberValue(v8::Isolate::GetCurrent()->GetCurrentContext())
+ .ToChecked();
+ double v2 = args[1]
+ ->NumberValue(v8::Isolate::GetCurrent()->GetCurrentContext())
+ .ToChecked();
+ args.GetReturnValue().Set(
+ v8::Number::New(v8::Isolate::GetCurrent(), v1 - v2));
+}
+
+// Returns a callable object. The object returns the difference of its two
+// parameters when it is called.
+RUNTIME_FUNCTION(Runtime_GetCallable) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 0);
+ v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
+ Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(v8_isolate);
+ Local<ObjectTemplate> instance_template = t->InstanceTemplate();
+ instance_template->SetCallAsFunctionHandler(call_as_function);
+ v8_isolate->GetCurrentContext();
+ Local<v8::Object> instance =
+ t->GetFunction(v8_isolate->GetCurrentContext())
+ .ToLocalChecked()
+ ->NewInstance(v8_isolate->GetCurrentContext())
+ .ToLocalChecked();
+ return *Utils::OpenHandle(*instance);
+}
RUNTIME_FUNCTION(Runtime_ClearFunctionTypeFeedback) {
HandleScope scope(isolate);
« no previous file with comments | « src/runtime/runtime.h ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698