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

Side by Side Diff: src/wasm/wasm-js.cc

Issue 1660083002: Drop the compileRun + asmCompileRun methods from wasm. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix Created 4 years, 10 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 | « no previous file | test/mjsunit/regress/regress-575364.js » ('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 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 "src/api.h" 5 #include "src/api.h"
6 #include "src/api-natives.h" 6 #include "src/api-natives.h"
7 #include "src/assert-scope.h" 7 #include "src/assert-scope.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/factory.h" 10 #include "src/factory.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 93 }
94 94
95 if (result.failed()) { 95 if (result.failed()) {
96 thrower.Failed("", result); 96 thrower.Failed("", result);
97 } 97 }
98 98
99 if (result.val) delete result.val; 99 if (result.val) delete result.val;
100 } 100 }
101 101
102 102
103 void CompileRun(const v8::FunctionCallbackInfo<v8::Value>& args) {
104 HandleScope scope(args.GetIsolate());
105 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
106 ErrorThrower thrower(isolate, "WASM.compileRun()");
107
108 RawBuffer buffer = GetRawBufferArgument(thrower, args);
109 if (thrower.error()) return;
110
111 // Decode and pre-verify the functions before compiling and running.
112 i::Zone zone;
113 internal::wasm::ModuleResult result = internal::wasm::DecodeWasmModule(
114 isolate, &zone, buffer.start, buffer.end, true, false);
115
116 if (result.failed()) {
117 thrower.Failed("", result);
118 } else {
119 // Success. Compile and run!
120 int32_t retval = i::wasm::CompileAndRunWasmModule(isolate, result.val);
121 args.GetReturnValue().Set(retval);
122 }
123
124 if (result.val) delete result.val;
125 }
126
127
128 v8::internal::wasm::WasmModuleIndex* TranslateAsmModule(i::ParseInfo* info, 103 v8::internal::wasm::WasmModuleIndex* TranslateAsmModule(i::ParseInfo* info,
129 ErrorThrower* thrower) { 104 ErrorThrower* thrower) {
130 info->set_global(); 105 info->set_global();
131 info->set_lazy(false); 106 info->set_lazy(false);
132 info->set_allow_lazy_parsing(false); 107 info->set_allow_lazy_parsing(false);
133 info->set_toplevel(true); 108 info->set_toplevel(true);
134 109
135 if (!i::Compiler::ParseAndAnalyze(info)) { 110 if (!i::Compiler::ParseAndAnalyze(info)) {
136 return nullptr; 111 return nullptr;
137 } 112 }
(...skipping 11 matching lines...) Expand all
149 return nullptr; 124 return nullptr;
150 } 125 }
151 126
152 auto module = v8::internal::wasm::AsmWasmBuilder( 127 auto module = v8::internal::wasm::AsmWasmBuilder(
153 info->isolate(), info->zone(), info->literal()) 128 info->isolate(), info->zone(), info->literal())
154 .Run(); 129 .Run();
155 return module; 130 return module;
156 } 131 }
157 132
158 133
159 void AsmCompileRun(const v8::FunctionCallbackInfo<v8::Value>& args) {
160 HandleScope scope(args.GetIsolate());
161 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
162 ErrorThrower thrower(isolate, "WASM.asmCompileRun()");
163
164 if (args.Length() != 1) {
165 thrower.Error("Invalid argument count");
166 return;
167 }
168 if (!args[0]->IsString()) {
169 thrower.Error("Asm module text should be a string");
170 return;
171 }
172
173 i::Factory* factory = isolate->factory();
174 i::Zone zone;
175 Local<String> source = Local<String>::Cast(args[0]);
176 i::Handle<i::Script> script = factory->NewScript(Utils::OpenHandle(*source));
177 i::ParseInfo info(&zone, script);
178
179 auto module = TranslateAsmModule(&info, &thrower);
180 if (module == nullptr) {
181 return;
182 }
183
184 int32_t result = v8::internal::wasm::CompileAndRunWasmModule(
185 isolate, module->Begin(), module->End(), true);
186 args.GetReturnValue().Set(result);
187 }
188
189
190 void InstantiateModuleCommon(const v8::FunctionCallbackInfo<v8::Value>& args, 134 void InstantiateModuleCommon(const v8::FunctionCallbackInfo<v8::Value>& args,
191 const byte* start, const byte* end, 135 const byte* start, const byte* end,
192 ErrorThrower* thrower, bool must_decode) { 136 ErrorThrower* thrower, bool must_decode) {
193 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); 137 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
194 138
195 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); 139 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null();
196 if (args.Length() > 2 && args[2]->IsArrayBuffer()) { 140 if (args.Length() > 2 && args[2]->IsArrayBuffer()) {
197 Local<Object> obj = Local<Object>::Cast(args[2]); 141 Local<Object> obj = Local<Object>::Cast(args[2]);
198 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); 142 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj);
199 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj)); 143 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj));
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 Handle<String> name = v8_str(isolate, "_WASMEXP_"); 249 Handle<String> name = v8_str(isolate, "_WASMEXP_");
306 Handle<JSFunction> cons = factory->NewFunction(name); 250 Handle<JSFunction> cons = factory->NewFunction(name);
307 JSFunction::SetInstancePrototype( 251 JSFunction::SetInstancePrototype(
308 cons, Handle<Object>(context->initial_object_prototype(), isolate)); 252 cons, Handle<Object>(context->initial_object_prototype(), isolate));
309 cons->shared()->set_instance_class_name(*name); 253 cons->shared()->set_instance_class_name(*name);
310 Handle<JSObject> wasm_object = factory->NewJSObject(cons, TENURED); 254 Handle<JSObject> wasm_object = factory->NewJSObject(cons, TENURED);
311 PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM); 255 PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM);
312 JSObject::AddProperty(global, name, wasm_object, attributes); 256 JSObject::AddProperty(global, name, wasm_object, attributes);
313 257
314 // Install functions on the WASM object. 258 // Install functions on the WASM object.
315 InstallFunc(isolate, wasm_object, "instantiateModule", InstantiateModule);
316 InstallFunc(isolate, wasm_object, "verifyModule", VerifyModule); 259 InstallFunc(isolate, wasm_object, "verifyModule", VerifyModule);
317 InstallFunc(isolate, wasm_object, "verifyFunction", VerifyFunction); 260 InstallFunc(isolate, wasm_object, "verifyFunction", VerifyFunction);
318 InstallFunc(isolate, wasm_object, "compileRun", CompileRun); 261 InstallFunc(isolate, wasm_object, "instantiateModule", InstantiateModule);
319 InstallFunc(isolate, wasm_object, "asmCompileRun", AsmCompileRun);
320 InstallFunc(isolate, wasm_object, "instantiateModuleFromAsm", 262 InstallFunc(isolate, wasm_object, "instantiateModuleFromAsm",
321 InstantiateModuleFromAsm); 263 InstantiateModuleFromAsm);
322 } 264 }
323 265
324 266
325 void WasmJs::InstallWasmFunctionMap(Isolate* isolate, Handle<Context> context) { 267 void WasmJs::InstallWasmFunctionMap(Isolate* isolate, Handle<Context> context) {
326 if (!context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) { 268 if (!context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) {
327 Handle<Map> wasm_function_map = isolate->factory()->NewMap( 269 Handle<Map> wasm_function_map = isolate->factory()->NewMap(
328 JS_FUNCTION_TYPE, JSFunction::kSize + kPointerSize); 270 JS_FUNCTION_TYPE, JSFunction::kSize + kPointerSize);
329 wasm_function_map->set_is_callable(); 271 wasm_function_map->set_is_callable();
330 context->set_wasm_function_map(*wasm_function_map); 272 context->set_wasm_function_map(*wasm_function_map);
331 } 273 }
332 } 274 }
333 275
334 } // namespace internal 276 } // namespace internal
335 } // namespace v8 277 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-575364.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698