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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 isolate->ThrowException(e); | 118 isolate->ThrowException(e); |
119 return false; | 119 return false; |
120 } | 120 } |
121 | 121 |
122 void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) { | 122 void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) { |
123 v8::Isolate* isolate = args.GetIsolate(); | 123 v8::Isolate* isolate = args.GetIsolate(); |
124 HandleScope scope(isolate); | 124 HandleScope scope(isolate); |
125 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate), | 125 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate), |
126 "WebAssembly.compile()"); | 126 "WebAssembly.compile()"); |
127 | 127 |
| 128 Local<Context> context = isolate->GetCurrentContext(); |
| 129 v8::Local<v8::Promise::Resolver> resolver; |
| 130 if (!v8::Promise::Resolver::New(context).ToLocal(&resolver)) return; |
| 131 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
| 132 return_value.Set(resolver->GetPromise()); |
| 133 |
128 if (args.Length() < 1) { | 134 if (args.Length() < 1) { |
129 thrower.TypeError("Argument 0 must be a buffer source"); | 135 thrower.TypeError("Argument 0 must be a buffer source"); |
| 136 resolver->Reject(context, Utils::ToLocal(thrower.Reify())); |
130 return; | 137 return; |
131 } | 138 } |
132 i::MaybeHandle<i::JSObject> module_obj = | 139 i::MaybeHandle<i::JSObject> module_obj = |
133 CreateModuleObject(isolate, args[0], &thrower); | 140 CreateModuleObject(isolate, args[0], &thrower); |
134 | 141 |
135 Local<Context> context = isolate->GetCurrentContext(); | |
136 v8::Local<v8::Promise::Resolver> resolver; | |
137 if (!v8::Promise::Resolver::New(context).ToLocal(&resolver)) return; | |
138 if (thrower.error()) { | 142 if (thrower.error()) { |
139 resolver->Reject(context, Utils::ToLocal(thrower.Reify())); | 143 resolver->Reject(context, Utils::ToLocal(thrower.Reify())); |
140 } else { | 144 } else { |
141 resolver->Resolve(context, Utils::ToLocal(module_obj.ToHandleChecked())); | 145 resolver->Resolve(context, Utils::ToLocal(module_obj.ToHandleChecked())); |
142 } | 146 } |
143 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | |
144 return_value.Set(resolver->GetPromise()); | |
145 } | 147 } |
146 | 148 |
147 void WebAssemblyValidate(const v8::FunctionCallbackInfo<v8::Value>& args) { | 149 void WebAssemblyValidate(const v8::FunctionCallbackInfo<v8::Value>& args) { |
148 v8::Isolate* isolate = args.GetIsolate(); | 150 v8::Isolate* isolate = args.GetIsolate(); |
149 HandleScope scope(isolate); | 151 HandleScope scope(isolate); |
150 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate), | 152 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate), |
151 "WebAssembly.validate()"); | 153 "WebAssembly.validate()"); |
152 | 154 |
153 if (args.Length() < 1) { | 155 if (args.Length() < 1) { |
154 thrower.TypeError("Argument 0 must be a buffer source"); | 156 thrower.TypeError("Argument 0 must be a buffer source"); |
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); | 905 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); |
904 return HasBrand(value, symbol); | 906 return HasBrand(value, symbol); |
905 } | 907 } |
906 | 908 |
907 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { | 909 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { |
908 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); | 910 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); |
909 return HasBrand(value, symbol); | 911 return HasBrand(value, symbol); |
910 } | 912 } |
911 } // namespace internal | 913 } // namespace internal |
912 } // namespace v8 | 914 } // namespace v8 |
OLD | NEW |