OLD | NEW |
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-natives.h" | 5 #include "src/api-natives.h" |
6 #include "src/api.h" | 6 #include "src/api.h" |
7 #include "src/asmjs/asm-js.h" | 7 #include "src/asmjs/asm-js.h" |
8 #include "src/asmjs/asm-typer.h" | 8 #include "src/asmjs/asm-typer.h" |
9 #include "src/asmjs/asm-wasm-builder.h" | 9 #include "src/asmjs/asm-wasm-builder.h" |
10 #include "src/assert-scope.h" | 10 #include "src/assert-scope.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 static i::MaybeHandle<i::JSObject> CreateModuleObject( | 188 static i::MaybeHandle<i::JSObject> CreateModuleObject( |
189 v8::Isolate* isolate, const v8::Local<v8::Value> source, | 189 v8::Isolate* isolate, const v8::Local<v8::Value> source, |
190 ErrorThrower* thrower) { | 190 ErrorThrower* thrower) { |
191 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 191 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
192 i::MaybeHandle<i::JSObject> nothing; | 192 i::MaybeHandle<i::JSObject> nothing; |
193 | 193 |
194 RawBuffer buffer = GetRawBufferSource(source, thrower); | 194 RawBuffer buffer = GetRawBufferSource(source, thrower); |
195 if (buffer.start == nullptr) return i::MaybeHandle<i::JSObject>(); | 195 if (buffer.start == nullptr) return i::MaybeHandle<i::JSObject>(); |
196 | 196 |
197 DCHECK(source->IsArrayBuffer() || source->IsTypedArray()); | 197 DCHECK(source->IsArrayBuffer() || source->IsTypedArray()); |
198 i::Zone zone(i_isolate->allocator()); | 198 return i::wasm::CreateModuleObjectFromBytes( |
199 i::wasm::ModuleResult result = i::wasm::DecodeWasmModule( | 199 i_isolate, buffer.start, buffer.end, thrower, |
200 i_isolate, &zone, buffer.start, buffer.end, false, i::wasm::kWasmOrigin); | 200 i::wasm::ModuleOrigin::kWasmOrigin); |
201 std::unique_ptr<const i::wasm::WasmModule> decoded_module(result.val); | |
202 if (result.failed()) { | |
203 thrower->Failed("", result); | |
204 return nothing; | |
205 } | |
206 i::MaybeHandle<i::FixedArray> compiled_module = | |
207 decoded_module->CompileFunctions(i_isolate, thrower); | |
208 if (compiled_module.is_null()) return nothing; | |
209 | |
210 return i::wasm::CreateCompiledModuleObject(i_isolate, | |
211 compiled_module.ToHandleChecked()); | |
212 } | 201 } |
213 | 202 |
214 void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) { | 203 void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) { |
215 v8::Isolate* isolate = args.GetIsolate(); | 204 v8::Isolate* isolate = args.GetIsolate(); |
216 HandleScope scope(isolate); | 205 HandleScope scope(isolate); |
217 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate), | 206 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate), |
218 "WebAssembly.compile()"); | 207 "WebAssembly.compile()"); |
219 | 208 |
220 if (args.Length() < 1) { | 209 if (args.Length() < 1) { |
221 thrower.Error("Argument 0 must be a buffer source"); | 210 thrower.Error("Argument 0 must be a buffer source"); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 int unused_property_fields = in_object_properties - pre_allocated; | 425 int unused_property_fields = in_object_properties - pre_allocated; |
437 Handle<Map> map = Map::CopyInitialMap( | 426 Handle<Map> map = Map::CopyInitialMap( |
438 prev_map, instance_size, in_object_properties, unused_property_fields); | 427 prev_map, instance_size, in_object_properties, unused_property_fields); |
439 | 428 |
440 context->set_wasm_function_map(*map); | 429 context->set_wasm_function_map(*map); |
441 } | 430 } |
442 } | 431 } |
443 | 432 |
444 } // namespace internal | 433 } // namespace internal |
445 } // namespace v8 | 434 } // namespace v8 |
OLD | NEW |