OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/assembler-inl.h" | 10 #include "src/assembler-inl.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 DCHECK_GT(g_PerIsolateWasmControls.Get().count(isolate), 0); | 38 DCHECK_GT(g_PerIsolateWasmControls.Get().count(isolate), 0); |
39 const WasmCompileControls& ctrls = g_PerIsolateWasmControls.Get().at(isolate); | 39 const WasmCompileControls& ctrls = g_PerIsolateWasmControls.Get().at(isolate); |
40 return (is_async && ctrls.AllowAnySizeForAsync) || | 40 return (is_async && ctrls.AllowAnySizeForAsync) || |
41 (v8::Local<v8::ArrayBuffer>::Cast(value)->ByteLength() <= | 41 (v8::Local<v8::ArrayBuffer>::Cast(value)->ByteLength() <= |
42 ctrls.MaxWasmBufferSize); | 42 ctrls.MaxWasmBufferSize); |
43 } | 43 } |
44 | 44 |
45 // Use the compile controls for instantiation, too | 45 // Use the compile controls for instantiation, too |
46 bool IsWasmInstantiateAllowed(v8::Isolate* isolate, | 46 bool IsWasmInstantiateAllowed(v8::Isolate* isolate, |
47 v8::Local<v8::Value> module_or_bytes, | 47 v8::Local<v8::Value> module_or_bytes, |
48 v8::MaybeLocal<v8::Value> ffi, bool is_async) { | 48 bool is_async) { |
49 DCHECK_GT(g_PerIsolateWasmControls.Get().count(isolate), 0); | 49 DCHECK_GT(g_PerIsolateWasmControls.Get().count(isolate), 0); |
50 const WasmCompileControls& ctrls = g_PerIsolateWasmControls.Get().at(isolate); | 50 const WasmCompileControls& ctrls = g_PerIsolateWasmControls.Get().at(isolate); |
51 if (is_async && ctrls.AllowAnySizeForAsync) return true; | 51 if (is_async && ctrls.AllowAnySizeForAsync) return true; |
52 if (!module_or_bytes->IsWebAssemblyCompiledModule()) { | 52 if (!module_or_bytes->IsWebAssemblyCompiledModule()) { |
53 return IsWasmCompileAllowed(isolate, module_or_bytes, is_async); | 53 return IsWasmCompileAllowed(isolate, module_or_bytes, is_async); |
54 } | 54 } |
55 v8::Local<v8::WasmCompiledModule> module = | 55 v8::Local<v8::WasmCompiledModule> module = |
56 v8::Local<v8::WasmCompiledModule>::Cast(module_or_bytes); | 56 v8::Local<v8::WasmCompiledModule>::Cast(module_or_bytes); |
57 return static_cast<uint32_t>(module->GetWasmWireBytes()->Length()) <= | 57 return static_cast<uint32_t>(module->GetWasmWireBytes()->Length()) <= |
58 ctrls.MaxWasmBufferSize; | 58 ctrls.MaxWasmBufferSize; |
59 } | 59 } |
60 | |
61 v8::Local<v8::Value> NewRangeException(v8::Isolate* isolate, | |
62 const char* message) { | |
63 return v8::Exception::RangeError( | |
64 v8::String::NewFromOneByte(isolate, | |
65 reinterpret_cast<const uint8_t*>(message), | |
66 v8::NewStringType::kNormal) | |
67 .ToLocalChecked()); | |
68 } | |
69 | |
70 void ThrowRangeException(v8::Isolate* isolate, const char* message) { | |
71 isolate->ThrowException(NewRangeException(isolate, message)); | |
72 } | |
73 | |
74 void RejectPromiseWithRangeError( | |
75 const v8::FunctionCallbackInfo<v8::Value>& args, const char* message) { | |
76 v8::Isolate* isolate = args.GetIsolate(); | |
77 v8::HandleScope scope(isolate); | |
78 | |
79 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
80 v8::Local<v8::Promise::Resolver> resolver; | |
81 if (!v8::Promise::Resolver::New(context).ToLocal(&resolver)) return; | |
82 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | |
83 return_value.Set(resolver->GetPromise()); | |
84 | |
85 auto maybe = resolver->Reject(context, NewRangeException(isolate, message)); | |
86 CHECK(!maybe.IsNothing()); | |
87 return; | |
88 } | |
89 | |
90 bool WasmModuleOverride(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
91 if (IsWasmCompileAllowed(args.GetIsolate(), args[0], false)) return false; | |
92 ThrowRangeException(args.GetIsolate(), "Sync compile not allowed"); | |
bradnelson
2017/03/24 17:45:24
Did we want to mention wasm in the error messages?
Mircea Trofin
2017/03/24 17:57:55
Why bother, it's a test :)
| |
93 return true; | |
94 } | |
95 | |
96 bool WasmCompileOverride(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
97 if (IsWasmCompileAllowed(args.GetIsolate(), args[0], true)) return false; | |
98 RejectPromiseWithRangeError(args, "Async compile not allowed"); | |
99 return true; | |
100 } | |
101 | |
102 bool WasmInstanceOverride(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
103 if (IsWasmInstantiateAllowed(args.GetIsolate(), args[0], false)) return false; | |
104 ThrowRangeException(args.GetIsolate(), "Sync instantiate not allowed"); | |
105 return true; | |
106 } | |
107 | |
108 bool WasmInstantiateOverride(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
109 if (IsWasmInstantiateAllowed(args.GetIsolate(), args[0], true)) return false; | |
110 RejectPromiseWithRangeError(args, "Async instantiate not allowed"); | |
111 return true; | |
112 } | |
113 | |
60 } // namespace | 114 } // namespace |
61 | 115 |
62 namespace v8 { | 116 namespace v8 { |
63 namespace internal { | 117 namespace internal { |
64 | 118 |
65 RUNTIME_FUNCTION(Runtime_ConstructDouble) { | 119 RUNTIME_FUNCTION(Runtime_ConstructDouble) { |
66 HandleScope scope(isolate); | 120 HandleScope scope(isolate); |
67 DCHECK_EQ(2, args.length()); | 121 DCHECK_EQ(2, args.length()); |
68 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]); | 122 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]); |
69 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]); | 123 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]); |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
509 | 563 |
510 RUNTIME_FUNCTION(Runtime_SetWasmCompileControls) { | 564 RUNTIME_FUNCTION(Runtime_SetWasmCompileControls) { |
511 HandleScope scope(isolate); | 565 HandleScope scope(isolate); |
512 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 566 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
513 CHECK(args.length() == 2); | 567 CHECK(args.length() == 2); |
514 CONVERT_ARG_HANDLE_CHECKED(Smi, block_size, 0); | 568 CONVERT_ARG_HANDLE_CHECKED(Smi, block_size, 0); |
515 CONVERT_BOOLEAN_ARG_CHECKED(allow_async, 1); | 569 CONVERT_BOOLEAN_ARG_CHECKED(allow_async, 1); |
516 WasmCompileControls& ctrl = (*g_PerIsolateWasmControls.Pointer())[v8_isolate]; | 570 WasmCompileControls& ctrl = (*g_PerIsolateWasmControls.Pointer())[v8_isolate]; |
517 ctrl.AllowAnySizeForAsync = allow_async; | 571 ctrl.AllowAnySizeForAsync = allow_async; |
518 ctrl.MaxWasmBufferSize = static_cast<uint32_t>(block_size->value()); | 572 ctrl.MaxWasmBufferSize = static_cast<uint32_t>(block_size->value()); |
519 isolate->set_allow_wasm_compile_callback(IsWasmCompileAllowed); | 573 v8_isolate->SetWasmModuleCallback(WasmModuleOverride); |
574 v8_isolate->SetWasmCompileCallback(WasmCompileOverride); | |
520 return isolate->heap()->undefined_value(); | 575 return isolate->heap()->undefined_value(); |
521 } | 576 } |
522 | 577 |
523 RUNTIME_FUNCTION(Runtime_SetWasmInstantiateControls) { | 578 RUNTIME_FUNCTION(Runtime_SetWasmInstantiateControls) { |
524 HandleScope scope(isolate); | 579 HandleScope scope(isolate); |
580 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | |
525 CHECK(args.length() == 0); | 581 CHECK(args.length() == 0); |
526 isolate->set_allow_wasm_instantiate_callback(IsWasmInstantiateAllowed); | 582 v8_isolate->SetWasmInstanceCallback(WasmInstanceOverride); |
583 v8_isolate->SetWasmInstantiateCallback(WasmInstantiateOverride); | |
527 return isolate->heap()->undefined_value(); | 584 return isolate->heap()->undefined_value(); |
528 } | 585 } |
529 | 586 |
530 RUNTIME_FUNCTION(Runtime_NotifyContextDisposed) { | 587 RUNTIME_FUNCTION(Runtime_NotifyContextDisposed) { |
531 HandleScope scope(isolate); | 588 HandleScope scope(isolate); |
532 DCHECK_EQ(0, args.length()); | 589 DCHECK_EQ(0, args.length()); |
533 isolate->heap()->NotifyContextDisposed(true); | 590 isolate->heap()->NotifyContextDisposed(true); |
534 return isolate->heap()->undefined_value(); | 591 return isolate->heap()->undefined_value(); |
535 } | 592 } |
536 | 593 |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
976 isolate->IncrementWaitCountForTesting(); | 1033 isolate->IncrementWaitCountForTesting(); |
977 return isolate->heap()->undefined_value(); | 1034 return isolate->heap()->undefined_value(); |
978 } | 1035 } |
979 | 1036 |
980 RUNTIME_FUNCTION(Runtime_DecrementWaitCount) { | 1037 RUNTIME_FUNCTION(Runtime_DecrementWaitCount) { |
981 isolate->DecrementWaitCountForTesting(); | 1038 isolate->DecrementWaitCountForTesting(); |
982 return isolate->heap()->undefined_value(); | 1039 return isolate->heap()->undefined_value(); |
983 } | 1040 } |
984 } // namespace internal | 1041 } // namespace internal |
985 } // namespace v8 | 1042 } // namespace v8 |
OLD | NEW |