Chromium Code Reviews| 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, false, |
| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 if (!FLAG_expose_wasm && !FLAG_validate_asm) { | 332 if (!FLAG_expose_wasm && !FLAG_validate_asm) { |
| 344 return; | 333 return; |
| 345 } | 334 } |
| 346 | 335 |
| 347 Factory* factory = isolate->factory(); | 336 Factory* factory = isolate->factory(); |
| 348 | 337 |
| 349 // Setup wasm function map. | 338 // Setup wasm function map. |
| 350 Handle<Context> context(global->native_context(), isolate); | 339 Handle<Context> context(global->native_context(), isolate); |
| 351 InstallWasmFunctionMap(isolate, context); | 340 InstallWasmFunctionMap(isolate, context); |
| 352 | 341 |
| 353 if (!FLAG_expose_wasm) { | |
|
bradnelson
2016/09/01 03:48:31
I don't think you want to drop this.
This will mak
Mircea Trofin
2016/09/01 04:36:17
Done.
| |
| 354 return; | |
| 355 } | |
| 356 | |
| 357 // Bind the experimental WASM object. | 342 // Bind the experimental WASM object. |
| 358 // TODO(rossberg, titzer): remove once it's no longer needed. | 343 // TODO(rossberg, titzer): remove once it's no longer needed. |
| 359 { | 344 { |
| 360 Handle<String> name = v8_str(isolate, "Wasm"); | 345 Handle<String> name = v8_str(isolate, "Wasm"); |
| 361 Handle<JSFunction> cons = factory->NewFunction(name); | 346 Handle<JSFunction> cons = factory->NewFunction(name); |
| 362 JSFunction::SetInstancePrototype( | 347 JSFunction::SetInstancePrototype( |
| 363 cons, Handle<Object>(context->initial_object_prototype(), isolate)); | 348 cons, Handle<Object>(context->initial_object_prototype(), isolate)); |
| 364 cons->shared()->set_instance_class_name(*name); | 349 cons->shared()->set_instance_class_name(*name); |
| 365 Handle<JSObject> wasm_object = factory->NewJSObject(cons, TENURED); | 350 Handle<JSObject> wasm_object = factory->NewJSObject(cons, TENURED); |
| 366 PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM); | 351 PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 int unused_property_fields = in_object_properties - pre_allocated; | 421 int unused_property_fields = in_object_properties - pre_allocated; |
| 437 Handle<Map> map = Map::CopyInitialMap( | 422 Handle<Map> map = Map::CopyInitialMap( |
| 438 prev_map, instance_size, in_object_properties, unused_property_fields); | 423 prev_map, instance_size, in_object_properties, unused_property_fields); |
| 439 | 424 |
| 440 context->set_wasm_function_map(*map); | 425 context->set_wasm_function_map(*map); |
| 441 } | 426 } |
| 442 } | 427 } |
| 443 | 428 |
| 444 } // namespace internal | 429 } // namespace internal |
| 445 } // namespace v8 | 430 } // namespace v8 |
| OLD | NEW |