Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: src/wasm/wasm-js.cc

Issue 1742073002: [wasm] Properly plumb the origin of the WASM module from asm.js translation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/module-decoder.cc ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 void VerifyModule(const v8::FunctionCallbackInfo<v8::Value>& args) { 58 void VerifyModule(const v8::FunctionCallbackInfo<v8::Value>& args) {
59 HandleScope scope(args.GetIsolate()); 59 HandleScope scope(args.GetIsolate());
60 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); 60 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
61 ErrorThrower thrower(isolate, "WASM.verifyModule()"); 61 ErrorThrower thrower(isolate, "WASM.verifyModule()");
62 62
63 RawBuffer buffer = GetRawBufferArgument(thrower, args); 63 RawBuffer buffer = GetRawBufferArgument(thrower, args);
64 if (thrower.error()) return; 64 if (thrower.error()) return;
65 65
66 i::Zone zone; 66 i::Zone zone;
67 internal::wasm::ModuleResult result = internal::wasm::DecodeWasmModule( 67 internal::wasm::ModuleResult result =
68 isolate, &zone, buffer.start, buffer.end, true, false); 68 internal::wasm::DecodeWasmModule(isolate, &zone, buffer.start, buffer.end,
69 true, internal::wasm::kWasmOrigin);
69 70
70 if (result.failed()) { 71 if (result.failed()) {
71 thrower.Failed("", result); 72 thrower.Failed("", result);
72 } 73 }
73 74
74 if (result.val) delete result.val; 75 if (result.val) delete result.val;
75 } 76 }
76 77
77 78
78 void VerifyFunction(const v8::FunctionCallbackInfo<v8::Value>& args) { 79 void VerifyFunction(const v8::FunctionCallbackInfo<v8::Value>& args) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 FILE* wasm_file = fopen(i::FLAG_asmjs_wasm_dumpfile, "wb"); 133 FILE* wasm_file = fopen(i::FLAG_asmjs_wasm_dumpfile, "wb");
133 if (wasm_file) { 134 if (wasm_file) {
134 fwrite(module->Begin(), module->End() - module->Begin(), 1, wasm_file); 135 fwrite(module->Begin(), module->End() - module->Begin(), 1, wasm_file);
135 fclose(wasm_file); 136 fclose(wasm_file);
136 } 137 }
137 } 138 }
138 139
139 return module; 140 return module;
140 } 141 }
141 142
142
143 void InstantiateModuleCommon(const v8::FunctionCallbackInfo<v8::Value>& args, 143 void InstantiateModuleCommon(const v8::FunctionCallbackInfo<v8::Value>& args,
144 const byte* start, const byte* end, 144 const byte* start, const byte* end,
145 ErrorThrower* thrower, bool must_decode) { 145 ErrorThrower* thrower,
146 internal::wasm::ModuleOrigin origin) {
146 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); 147 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
147 148
148 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); 149 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null();
149 if (args.Length() > 2 && args[2]->IsArrayBuffer()) { 150 if (args.Length() > 2 && args[2]->IsArrayBuffer()) {
150 Local<Object> obj = Local<Object>::Cast(args[2]); 151 Local<Object> obj = Local<Object>::Cast(args[2]);
151 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); 152 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj);
152 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj)); 153 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj));
153 } 154 }
154 155
155 // Decode but avoid a redundant pass over function bodies for verification. 156 // Decode but avoid a redundant pass over function bodies for verification.
156 // Verification will happen during compilation. 157 // Verification will happen during compilation.
157 i::Zone zone; 158 i::Zone zone;
158 internal::wasm::ModuleResult result = internal::wasm::DecodeWasmModule( 159 internal::wasm::ModuleResult result = internal::wasm::DecodeWasmModule(
159 isolate, &zone, start, end, false, false); 160 isolate, &zone, start, end, false, origin);
160 161
161 if (result.failed() && must_decode) { 162 if (result.failed() && origin == internal::wasm::kAsmJsOrigin) {
162 thrower->Error("Asm.js converted module failed to decode"); 163 thrower->Error("Asm.js converted module failed to decode");
163 } else if (result.failed()) { 164 } else if (result.failed()) {
164 thrower->Failed("", result); 165 thrower->Failed("", result);
165 } else { 166 } else {
166 // Success. Instantiate the module and return the object. 167 // Success. Instantiate the module and return the object.
167 i::Handle<i::JSObject> ffi = i::Handle<i::JSObject>::null(); 168 i::Handle<i::JSObject> ffi = i::Handle<i::JSObject>::null();
168 if (args.Length() > 1 && args[1]->IsObject()) { 169 if (args.Length() > 1 && args[1]->IsObject()) {
169 Local<Object> obj = Local<Object>::Cast(args[1]); 170 Local<Object> obj = Local<Object>::Cast(args[1]);
170 ffi = i::Handle<i::JSObject>::cast(v8::Utils::OpenHandle(*obj)); 171 ffi = i::Handle<i::JSObject>::cast(v8::Utils::OpenHandle(*obj));
171 } 172 }
(...skipping 30 matching lines...) Expand all
202 if (args.Length() > 1 && args[1]->IsObject()) { 203 if (args.Length() > 1 && args[1]->IsObject()) {
203 Local<Object> local_foreign = Local<Object>::Cast(args[1]); 204 Local<Object> local_foreign = Local<Object>::Cast(args[1]);
204 foreign = v8::Utils::OpenHandle(*local_foreign); 205 foreign = v8::Utils::OpenHandle(*local_foreign);
205 } 206 }
206 207
207 auto module = TranslateAsmModule(&info, foreign, &thrower); 208 auto module = TranslateAsmModule(&info, foreign, &thrower);
208 if (module == nullptr) { 209 if (module == nullptr) {
209 return; 210 return;
210 } 211 }
211 212
212 InstantiateModuleCommon(args, module->Begin(), module->End(), &thrower, true); 213 InstantiateModuleCommon(args, module->Begin(), module->End(), &thrower,
214 internal::wasm::kAsmJsOrigin);
213 } 215 }
214 216
215 217
216 void InstantiateModule(const v8::FunctionCallbackInfo<v8::Value>& args) { 218 void InstantiateModule(const v8::FunctionCallbackInfo<v8::Value>& args) {
217 HandleScope scope(args.GetIsolate()); 219 HandleScope scope(args.GetIsolate());
218 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); 220 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
219 ErrorThrower thrower(isolate, "WASM.instantiateModule()"); 221 ErrorThrower thrower(isolate, "WASM.instantiateModule()");
220 222
221 RawBuffer buffer = GetRawBufferArgument(thrower, args); 223 RawBuffer buffer = GetRawBufferArgument(thrower, args);
222 if (buffer.start == nullptr) return; 224 if (buffer.start == nullptr) return;
223 225
224 InstantiateModuleCommon(args, buffer.start, buffer.end, &thrower, false); 226 InstantiateModuleCommon(args, buffer.start, buffer.end, &thrower,
227 internal::wasm::kWasmOrigin);
225 } 228 }
226 } // namespace 229 } // namespace
227 230
228 231
229 // TODO(titzer): we use the API to create the function template because the 232 // TODO(titzer): we use the API to create the function template because the
230 // internal guts are too ugly to replicate here. 233 // internal guts are too ugly to replicate here.
231 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate, 234 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate,
232 FunctionCallback func) { 235 FunctionCallback func) {
233 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); 236 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate);
234 Local<FunctionTemplate> local = FunctionTemplate::New(isolate, func); 237 Local<FunctionTemplate> local = FunctionTemplate::New(isolate, func);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 if (!context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) { 286 if (!context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) {
284 Handle<Map> wasm_function_map = isolate->factory()->NewMap( 287 Handle<Map> wasm_function_map = isolate->factory()->NewMap(
285 JS_FUNCTION_TYPE, JSFunction::kSize + kPointerSize); 288 JS_FUNCTION_TYPE, JSFunction::kSize + kPointerSize);
286 wasm_function_map->set_is_callable(); 289 wasm_function_map->set_is_callable();
287 context->set_wasm_function_map(*wasm_function_map); 290 context->set_wasm_function_map(*wasm_function_map);
288 } 291 }
289 } 292 }
290 293
291 } // namespace internal 294 } // namespace internal
292 } // namespace v8 295 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/module-decoder.cc ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698