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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/runtime/runtime.h ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/arguments.h" 9 #include "src/arguments.h"
10 #include "src/deoptimizer.h" 10 #include "src/deoptimizer.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 254
255 Local<v8::ObjectTemplate> desc = v8::ObjectTemplate::New(v8_isolate); 255 Local<v8::ObjectTemplate> desc = v8::ObjectTemplate::New(v8_isolate);
256 desc->MarkAsUndetectable(); 256 desc->MarkAsUndetectable();
257 Local<v8::Object> obj; 257 Local<v8::Object> obj;
258 if (!desc->NewInstance(v8_isolate->GetCurrentContext()).ToLocal(&obj)) { 258 if (!desc->NewInstance(v8_isolate->GetCurrentContext()).ToLocal(&obj)) {
259 return nullptr; 259 return nullptr;
260 } 260 }
261 return *Utils::OpenHandle(*obj); 261 return *Utils::OpenHandle(*obj);
262 } 262 }
263 263
264 static void call_as_function(const v8::FunctionCallbackInfo<v8::Value>& args) {
265 double v1 = args[0]
266 ->NumberValue(v8::Isolate::GetCurrent()->GetCurrentContext())
267 .ToChecked();
268 double v2 = args[1]
269 ->NumberValue(v8::Isolate::GetCurrent()->GetCurrentContext())
270 .ToChecked();
271 args.GetReturnValue().Set(
272 v8::Number::New(v8::Isolate::GetCurrent(), v1 - v2));
273 }
274
275 // Returns a callable object. The object returns the difference of its two
276 // parameters when it is called.
277 RUNTIME_FUNCTION(Runtime_GetCallable) {
278 HandleScope scope(isolate);
279 DCHECK(args.length() == 0);
280 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
281 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(v8_isolate);
282 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
283 instance_template->SetCallAsFunctionHandler(call_as_function);
284 v8_isolate->GetCurrentContext();
285 Local<v8::Object> instance =
286 t->GetFunction(v8_isolate->GetCurrentContext())
287 .ToLocalChecked()
288 ->NewInstance(v8_isolate->GetCurrentContext())
289 .ToLocalChecked();
290 return *Utils::OpenHandle(*instance);
291 }
264 292
265 RUNTIME_FUNCTION(Runtime_ClearFunctionTypeFeedback) { 293 RUNTIME_FUNCTION(Runtime_ClearFunctionTypeFeedback) {
266 HandleScope scope(isolate); 294 HandleScope scope(isolate);
267 DCHECK(args.length() == 1); 295 DCHECK(args.length() == 1);
268 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 296 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
269 function->ClearTypeFeedbackInfo(); 297 function->ClearTypeFeedbackInfo();
270 Code* unoptimized = function->shared()->code(); 298 Code* unoptimized = function->shared()->code();
271 if (unoptimized->kind() == Code::FUNCTION) { 299 if (unoptimized->kind() == Code::FUNCTION) {
272 unoptimized->ClearInlineCaches(); 300 unoptimized->ClearInlineCaches();
273 } 301 }
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 WasmCompiledModuleSerializer::DeserializeWasmModule(isolate, &sc); 693 WasmCompiledModuleSerializer::DeserializeWasmModule(isolate, &sc);
666 Handle<FixedArray> compiled_module; 694 Handle<FixedArray> compiled_module;
667 if (!maybe_compiled_module.ToHandle(&compiled_module)) { 695 if (!maybe_compiled_module.ToHandle(&compiled_module)) {
668 return isolate->heap()->undefined_value(); 696 return isolate->heap()->undefined_value();
669 } 697 }
670 return *wasm::CreateCompiledModuleObject(isolate, compiled_module); 698 return *wasm::CreateCompiledModuleObject(isolate, compiled_module);
671 } 699 }
672 700
673 } // namespace internal 701 } // namespace internal
674 } // namespace v8 702 } // namespace v8
OLDNEW
« 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