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.h" | 5 #include "src/api.h" |
6 #include "src/api-natives.h" | 6 #include "src/api-natives.h" |
7 #include "src/assert-scope.h" | 7 #include "src/assert-scope.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/factory.h" | 10 #include "src/factory.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 buffer.start, buffer.end); | 92 buffer.start, buffer.end); |
93 } | 93 } |
94 | 94 |
95 if (result.failed()) { | 95 if (result.failed()) { |
96 thrower.Failed("", result); | 96 thrower.Failed("", result); |
97 } | 97 } |
98 | 98 |
99 if (result.val) delete result.val; | 99 if (result.val) delete result.val; |
100 } | 100 } |
101 | 101 |
102 | 102 v8::internal::wasm::WasmModuleIndex* TranslateAsmModule( |
103 v8::internal::wasm::WasmModuleIndex* TranslateAsmModule(i::ParseInfo* info, | 103 i::ParseInfo* info, i::Handle<i::Object> foreign, ErrorThrower* thrower) { |
104 ErrorThrower* thrower) { | |
105 info->set_global(); | 104 info->set_global(); |
106 info->set_lazy(false); | 105 info->set_lazy(false); |
107 info->set_allow_lazy_parsing(false); | 106 info->set_allow_lazy_parsing(false); |
108 info->set_toplevel(true); | 107 info->set_toplevel(true); |
109 | 108 |
110 if (!i::Compiler::ParseAndAnalyze(info)) { | 109 if (!i::Compiler::ParseAndAnalyze(info)) { |
111 return nullptr; | 110 return nullptr; |
112 } | 111 } |
113 | 112 |
114 info->set_literal( | 113 info->set_literal( |
115 info->scope()->declarations()->at(0)->AsFunctionDeclaration()->fun()); | 114 info->scope()->declarations()->at(0)->AsFunctionDeclaration()->fun()); |
116 | 115 |
117 v8::internal::AsmTyper typer(info->isolate(), info->zone(), *(info->script()), | 116 v8::internal::AsmTyper typer(info->isolate(), info->zone(), *(info->script()), |
118 info->literal()); | 117 info->literal()); |
119 if (i::FLAG_enable_simd_asmjs) { | 118 if (i::FLAG_enable_simd_asmjs) { |
120 typer.set_allow_simd(true); | 119 typer.set_allow_simd(true); |
121 } | 120 } |
122 if (!typer.Validate()) { | 121 if (!typer.Validate()) { |
123 thrower->Error("Asm.js validation failed: %s", typer.error_message()); | 122 thrower->Error("Asm.js validation failed: %s", typer.error_message()); |
124 return nullptr; | 123 return nullptr; |
125 } | 124 } |
126 | 125 |
127 auto module = v8::internal::wasm::AsmWasmBuilder( | 126 auto module = v8::internal::wasm::AsmWasmBuilder( |
128 info->isolate(), info->zone(), info->literal()) | 127 info->isolate(), info->zone(), info->literal(), foreign) |
129 .Run(); | 128 .Run(); |
130 return module; | 129 return module; |
131 } | 130 } |
132 | 131 |
133 | 132 |
134 void InstantiateModuleCommon(const v8::FunctionCallbackInfo<v8::Value>& args, | 133 void InstantiateModuleCommon(const v8::FunctionCallbackInfo<v8::Value>& args, |
135 const byte* start, const byte* end, | 134 const byte* start, const byte* end, |
136 ErrorThrower* thrower, bool must_decode) { | 135 ErrorThrower* thrower, bool must_decode) { |
137 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); | 136 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); |
138 | 137 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 thrower.Error("Asm module text should be a string"); | 181 thrower.Error("Asm module text should be a string"); |
183 return; | 182 return; |
184 } | 183 } |
185 | 184 |
186 i::Factory* factory = isolate->factory(); | 185 i::Factory* factory = isolate->factory(); |
187 i::Zone zone; | 186 i::Zone zone; |
188 Local<String> source = Local<String>::Cast(args[0]); | 187 Local<String> source = Local<String>::Cast(args[0]); |
189 i::Handle<i::Script> script = factory->NewScript(Utils::OpenHandle(*source)); | 188 i::Handle<i::Script> script = factory->NewScript(Utils::OpenHandle(*source)); |
190 i::ParseInfo info(&zone, script); | 189 i::ParseInfo info(&zone, script); |
191 | 190 |
192 auto module = TranslateAsmModule(&info, &thrower); | 191 i::Handle<i::Object> foreign; |
| 192 if (args.Length() > 1 && args[1]->IsObject()) { |
| 193 Local<Object> local_foreign = Local<Object>::Cast(args[1]); |
| 194 foreign = v8::Utils::OpenHandle(*local_foreign); |
| 195 } |
| 196 |
| 197 auto module = TranslateAsmModule(&info, foreign, &thrower); |
193 if (module == nullptr) { | 198 if (module == nullptr) { |
194 return; | 199 return; |
195 } | 200 } |
196 | 201 |
197 InstantiateModuleCommon(args, module->Begin(), module->End(), &thrower, true); | 202 InstantiateModuleCommon(args, module->Begin(), module->End(), &thrower, true); |
198 } | 203 } |
199 | 204 |
200 | 205 |
201 void InstantiateModule(const v8::FunctionCallbackInfo<v8::Value>& args) { | 206 void InstantiateModule(const v8::FunctionCallbackInfo<v8::Value>& args) { |
202 HandleScope scope(args.GetIsolate()); | 207 HandleScope scope(args.GetIsolate()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 if (!context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) { | 273 if (!context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) { |
269 Handle<Map> wasm_function_map = isolate->factory()->NewMap( | 274 Handle<Map> wasm_function_map = isolate->factory()->NewMap( |
270 JS_FUNCTION_TYPE, JSFunction::kSize + kPointerSize); | 275 JS_FUNCTION_TYPE, JSFunction::kSize + kPointerSize); |
271 wasm_function_map->set_is_callable(); | 276 wasm_function_map->set_is_callable(); |
272 context->set_wasm_function_map(*wasm_function_map); | 277 context->set_wasm_function_map(*wasm_function_map); |
273 } | 278 } |
274 } | 279 } |
275 | 280 |
276 } // namespace internal | 281 } // namespace internal |
277 } // namespace v8 | 282 } // namespace v8 |
OLD | NEW |