| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 return {}; | 171 return {}; |
| 172 } | 172 } |
| 173 Local<Object> obj = Local<Object>::Cast(args[1]); | 173 Local<Object> obj = Local<Object>::Cast(args[1]); |
| 174 return i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); | 174 return i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); |
| 175 } | 175 } |
| 176 | 176 |
| 177 // WebAssembly.compile(bytes) -> Promise | 177 // WebAssembly.compile(bytes) -> Promise |
| 178 void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) { | 178 void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 179 v8::Isolate* isolate = args.GetIsolate(); | 179 v8::Isolate* isolate = args.GetIsolate(); |
| 180 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 180 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 181 if (i_isolate->wasm_compile_callback()(args)) return; |
| 182 |
| 181 HandleScope scope(isolate); | 183 HandleScope scope(isolate); |
| 182 ErrorThrower thrower(i_isolate, "WebAssembly.compile()"); | 184 ErrorThrower thrower(i_isolate, "WebAssembly.compile()"); |
| 183 | 185 |
| 184 Local<Context> context = isolate->GetCurrentContext(); | 186 Local<Context> context = isolate->GetCurrentContext(); |
| 185 v8::Local<v8::Promise::Resolver> resolver; | 187 v8::Local<v8::Promise::Resolver> resolver; |
| 186 if (!v8::Promise::Resolver::New(context).ToLocal(&resolver)) return; | 188 if (!v8::Promise::Resolver::New(context).ToLocal(&resolver)) return; |
| 187 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | 189 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
| 188 return_value.Set(resolver->GetPromise()); | 190 return_value.Set(resolver->GetPromise()); |
| 189 | 191 |
| 190 auto bytes = GetFirstArgumentAsBytes(args, &thrower); | 192 auto bytes = GetFirstArgumentAsBytes(args, &thrower); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 215 } else { | 217 } else { |
| 216 if (thrower.wasm_error()) thrower.Reify(); // Clear error. | 218 if (thrower.wasm_error()) thrower.Reify(); // Clear error. |
| 217 return_value.Set(v8::False(isolate)); | 219 return_value.Set(v8::False(isolate)); |
| 218 } | 220 } |
| 219 } | 221 } |
| 220 | 222 |
| 221 // new WebAssembly.Module(bytes) -> WebAssembly.Module | 223 // new WebAssembly.Module(bytes) -> WebAssembly.Module |
| 222 void WebAssemblyModule(const v8::FunctionCallbackInfo<v8::Value>& args) { | 224 void WebAssemblyModule(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 223 v8::Isolate* isolate = args.GetIsolate(); | 225 v8::Isolate* isolate = args.GetIsolate(); |
| 224 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 226 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 227 if (i_isolate->wasm_module_callback()(args)) return; |
| 228 |
| 225 HandleScope scope(isolate); | 229 HandleScope scope(isolate); |
| 226 ErrorThrower thrower(i_isolate, "WebAssembly.Module()"); | 230 ErrorThrower thrower(i_isolate, "WebAssembly.Module()"); |
| 227 | 231 |
| 228 auto bytes = GetFirstArgumentAsBytes(args, &thrower); | 232 auto bytes = GetFirstArgumentAsBytes(args, &thrower); |
| 229 if (!IsCompilationAllowed(i_isolate, &thrower, args[0], false)) return; | 233 if (!IsCompilationAllowed(i_isolate, &thrower, args[0], false)) return; |
| 230 | 234 |
| 231 DCHECK(!thrower.error()); | 235 DCHECK(!thrower.error()); |
| 232 i::MaybeHandle<i::Object> module_obj = | 236 i::MaybeHandle<i::Object> module_obj = |
| 233 i::wasm::SyncCompile(i_isolate, &thrower, bytes); | 237 i::wasm::SyncCompile(i_isolate, &thrower, bytes); |
| 234 if (module_obj.is_null()) return; | 238 if (module_obj.is_null()) return; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 i::Handle<i::String>::cast(name), &thrower); | 294 i::Handle<i::String>::cast(name), &thrower); |
| 291 if (thrower.error()) return; | 295 if (thrower.error()) return; |
| 292 args.GetReturnValue().Set(Utils::ToLocal(custom_sections)); | 296 args.GetReturnValue().Set(Utils::ToLocal(custom_sections)); |
| 293 } | 297 } |
| 294 | 298 |
| 295 // new WebAssembly.Instance(module, imports) -> WebAssembly.Instance | 299 // new WebAssembly.Instance(module, imports) -> WebAssembly.Instance |
| 296 void WebAssemblyInstance(const v8::FunctionCallbackInfo<v8::Value>& args) { | 300 void WebAssemblyInstance(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 297 HandleScope scope(args.GetIsolate()); | 301 HandleScope scope(args.GetIsolate()); |
| 298 v8::Isolate* isolate = args.GetIsolate(); | 302 v8::Isolate* isolate = args.GetIsolate(); |
| 299 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 303 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 304 if (i_isolate->wasm_instance_callback()(args)) return; |
| 305 |
| 300 ErrorThrower thrower(i_isolate, "WebAssembly.Instance()"); | 306 ErrorThrower thrower(i_isolate, "WebAssembly.Instance()"); |
| 301 | 307 |
| 302 auto maybe_module = GetFirstArgumentAsModule(args, &thrower); | 308 auto maybe_module = GetFirstArgumentAsModule(args, &thrower); |
| 303 if (thrower.error()) return; | 309 if (thrower.error()) return; |
| 304 | 310 |
| 305 auto maybe_imports = GetSecondArgumentAsImports(args, &thrower); | 311 auto maybe_imports = GetSecondArgumentAsImports(args, &thrower); |
| 306 if (!IsInstantiationAllowed(i_isolate, &thrower, args[0], maybe_imports, | 312 if (!IsInstantiationAllowed(i_isolate, &thrower, args[0], maybe_imports, |
| 307 false)) { | 313 false)) { |
| 308 return; | 314 return; |
| 309 } | 315 } |
| 310 DCHECK(!thrower.error()); | 316 DCHECK(!thrower.error()); |
| 311 | 317 |
| 312 i::MaybeHandle<i::Object> instance_object = i::wasm::SyncInstantiate( | 318 i::MaybeHandle<i::Object> instance_object = i::wasm::SyncInstantiate( |
| 313 i_isolate, &thrower, maybe_module.ToHandleChecked(), maybe_imports, | 319 i_isolate, &thrower, maybe_module.ToHandleChecked(), maybe_imports, |
| 314 i::MaybeHandle<i::JSArrayBuffer>()); | 320 i::MaybeHandle<i::JSArrayBuffer>()); |
| 315 if (instance_object.is_null()) return; | 321 if (instance_object.is_null()) return; |
| 316 args.GetReturnValue().Set(Utils::ToLocal(instance_object.ToHandleChecked())); | 322 args.GetReturnValue().Set(Utils::ToLocal(instance_object.ToHandleChecked())); |
| 317 } | 323 } |
| 318 | 324 |
| 319 // WebAssembly.instantiate(module, imports) -> WebAssembly.Instance | 325 // WebAssembly.instantiate(module, imports) -> WebAssembly.Instance |
| 320 // WebAssembly.instantiate(bytes, imports) -> | 326 // WebAssembly.instantiate(bytes, imports) -> |
| 321 // {module: WebAssembly.Module, instance: WebAssembly.Instance} | 327 // {module: WebAssembly.Module, instance: WebAssembly.Instance} |
| 322 void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) { | 328 void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 323 v8::Isolate* isolate = args.GetIsolate(); | 329 v8::Isolate* isolate = args.GetIsolate(); |
| 324 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 330 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 331 if (i_isolate->wasm_instantiate_callback()(args)) return; |
| 332 |
| 325 ErrorThrower thrower(i_isolate, "WebAssembly.instantiate()"); | 333 ErrorThrower thrower(i_isolate, "WebAssembly.instantiate()"); |
| 326 | 334 |
| 327 HandleScope scope(isolate); | 335 HandleScope scope(isolate); |
| 328 | 336 |
| 329 Local<Context> context = isolate->GetCurrentContext(); | 337 Local<Context> context = isolate->GetCurrentContext(); |
| 330 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); | 338 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); |
| 331 | 339 |
| 332 v8::Local<v8::Promise::Resolver> resolver; | 340 v8::Local<v8::Promise::Resolver> resolver; |
| 333 if (!v8::Promise::Resolver::New(context).ToLocal(&resolver)) return; | 341 if (!v8::Promise::Resolver::New(context).ToLocal(&resolver)) return; |
| 334 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | 342 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); | 932 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); |
| 925 return HasBrand(value, symbol); | 933 return HasBrand(value, symbol); |
| 926 } | 934 } |
| 927 | 935 |
| 928 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { | 936 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { |
| 929 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); | 937 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); |
| 930 return HasBrand(value, symbol); | 938 return HasBrand(value, symbol); |
| 931 } | 939 } |
| 932 } // namespace internal | 940 } // namespace internal |
| 933 } // namespace v8 | 941 } // namespace v8 |
| OLD | NEW |