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 14 matching lines...) Expand all Loading... |
25 #include "src/wasm/wasm-result.h" | 25 #include "src/wasm/wasm-result.h" |
26 | 26 |
27 typedef uint8_t byte; | 27 typedef uint8_t byte; |
28 | 28 |
29 using v8::internal::wasm::ErrorThrower; | 29 using v8::internal::wasm::ErrorThrower; |
30 | 30 |
31 namespace v8 { | 31 namespace v8 { |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 #define RANGE_ERROR_MSG \ | |
36 "Wasm compilation exceeds internal limits in this context for the provided " \ | |
37 "arguments" | |
38 | |
39 // TODO(wasm): move brand check to the respective types, and don't throw | 35 // TODO(wasm): move brand check to the respective types, and don't throw |
40 // in it, rather, use a provided ErrorThrower, or let caller handle it. | 36 // in it, rather, use a provided ErrorThrower, or let caller handle it. |
41 static bool HasBrand(i::Handle<i::Object> value, i::Handle<i::Symbol> sym) { | 37 static bool HasBrand(i::Handle<i::Object> value, i::Handle<i::Symbol> sym) { |
42 if (!value->IsJSObject()) return false; | 38 if (!value->IsJSObject()) return false; |
43 i::Handle<i::JSObject> object = i::Handle<i::JSObject>::cast(value); | 39 i::Handle<i::JSObject> object = i::Handle<i::JSObject>::cast(value); |
44 Maybe<bool> has_brand = i::JSObject::HasOwnProperty(object, sym); | 40 Maybe<bool> has_brand = i::JSObject::HasOwnProperty(object, sym); |
45 return has_brand.FromMaybe(false); | 41 return has_brand.FromMaybe(false); |
46 } | 42 } |
47 | 43 |
48 static bool BrandCheck(i::Handle<i::Object> value, i::Handle<i::Symbol> sym, | 44 static bool BrandCheck(i::Handle<i::Object> value, i::Handle<i::Symbol> sym, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 bool IsCompilationAllowed(i::Isolate* isolate, ErrorThrower* thrower, | 77 bool IsCompilationAllowed(i::Isolate* isolate, ErrorThrower* thrower, |
82 v8::Local<v8::Value> source, bool is_async) { | 78 v8::Local<v8::Value> source, bool is_async) { |
83 // Allow caller to do one final check on thrower state, rather than | 79 // Allow caller to do one final check on thrower state, rather than |
84 // one at each step. No information is lost - failure reason is captured | 80 // one at each step. No information is lost - failure reason is captured |
85 // in the thrower state. | 81 // in the thrower state. |
86 if (thrower->error()) return false; | 82 if (thrower->error()) return false; |
87 | 83 |
88 AllowWasmCompileCallback callback = isolate->allow_wasm_compile_callback(); | 84 AllowWasmCompileCallback callback = isolate->allow_wasm_compile_callback(); |
89 if (callback != nullptr && | 85 if (callback != nullptr && |
90 !callback(reinterpret_cast<v8::Isolate*>(isolate), source, is_async)) { | 86 !callback(reinterpret_cast<v8::Isolate*>(isolate), source, is_async)) { |
91 thrower->RangeError(RANGE_ERROR_MSG); | 87 thrower->RangeError( |
| 88 "%ssynchronous compilation disallowed due to module size limit set by " |
| 89 "embedder", |
| 90 is_async ? "a" : ""); |
92 return false; | 91 return false; |
93 } | 92 } |
94 return true; | 93 return true; |
95 } | 94 } |
96 | 95 |
97 bool IsInstantiationAllowed(i::Isolate* isolate, ErrorThrower* thrower, | 96 bool IsInstantiationAllowed(i::Isolate* isolate, ErrorThrower* thrower, |
98 v8::Local<v8::Value> module_or_bytes, | 97 v8::Local<v8::Value> module_or_bytes, |
99 i::MaybeHandle<i::JSReceiver> ffi, bool is_async) { | 98 i::MaybeHandle<i::JSReceiver> ffi, bool is_async) { |
100 // Allow caller to do one final check on thrower state, rather than | 99 // Allow caller to do one final check on thrower state, rather than |
101 // one at each step. No information is lost - failure reason is captured | 100 // one at each step. No information is lost - failure reason is captured |
102 // in the thrower state. | 101 // in the thrower state. |
103 if (thrower->error()) return false; | 102 if (thrower->error()) return false; |
104 v8::MaybeLocal<v8::Value> v8_ffi; | 103 v8::MaybeLocal<v8::Value> v8_ffi; |
105 if (!ffi.is_null()) { | 104 if (!ffi.is_null()) { |
106 v8_ffi = v8::Local<v8::Value>::Cast(Utils::ToLocal(ffi.ToHandleChecked())); | 105 v8_ffi = v8::Local<v8::Value>::Cast(Utils::ToLocal(ffi.ToHandleChecked())); |
107 } | 106 } |
108 AllowWasmInstantiateCallback callback = | 107 AllowWasmInstantiateCallback callback = |
109 isolate->allow_wasm_instantiate_callback(); | 108 isolate->allow_wasm_instantiate_callback(); |
110 if (callback != nullptr && | 109 if (callback != nullptr && |
111 !callback(reinterpret_cast<v8::Isolate*>(isolate), module_or_bytes, | 110 !callback(reinterpret_cast<v8::Isolate*>(isolate), module_or_bytes, |
112 v8_ffi, is_async)) { | 111 v8_ffi, is_async)) { |
113 thrower->RangeError(RANGE_ERROR_MSG); | 112 thrower->RangeError( |
| 113 "%ssynchronous instantiation disallowed due to module size limit set " |
| 114 "by embedder", |
| 115 is_async ? "a" : ""); |
114 return false; | 116 return false; |
115 } | 117 } |
116 return true; | 118 return true; |
117 } | 119 } |
118 | 120 |
119 i::wasm::ModuleWireBytes GetFirstArgumentAsBytes( | 121 i::wasm::ModuleWireBytes GetFirstArgumentAsBytes( |
120 const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) { | 122 const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) { |
121 if (args.Length() < 1) { | 123 if (args.Length() < 1) { |
122 thrower->TypeError("Argument 0 must be a buffer source"); | 124 thrower->TypeError("Argument 0 must be a buffer source"); |
123 return i::wasm::ModuleWireBytes(nullptr, nullptr); | 125 return i::wasm::ModuleWireBytes(nullptr, nullptr); |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); | 918 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); |
917 return HasBrand(value, symbol); | 919 return HasBrand(value, symbol); |
918 } | 920 } |
919 | 921 |
920 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { | 922 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { |
921 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); | 923 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); |
922 return HasBrand(value, symbol); | 924 return HasBrand(value, symbol); |
923 } | 925 } |
924 } // namespace internal | 926 } // namespace internal |
925 } // namespace v8 | 927 } // namespace v8 |
OLD | NEW |