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

Side by Side Diff: src/asmjs/asm-js.cc

Issue 2251433002: [wasm] asm.js - Check stdlib.NaN is valid, prepare for the rest. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix Created 4 years, 4 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
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/asmjs/asm-js.h" 5 #include "src/asmjs/asm-js.h"
6 6
7 #include "src/api-natives.h" 7 #include "src/api-natives.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/asmjs/asm-typer.h" 9 #include "src/asmjs/asm-typer.h"
10 #include "src/asmjs/asm-wasm-builder.h" 10 #include "src/asmjs/asm-wasm-builder.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 v8::internal::wasm::AsmWasmBuilder builder(info->isolate(), info->zone(), 67 v8::internal::wasm::AsmWasmBuilder builder(info->isolate(), info->zone(),
68 info->literal(), &typer); 68 info->literal(), &typer);
69 i::Handle<i::FixedArray> foreign_globals; 69 i::Handle<i::FixedArray> foreign_globals;
70 auto module = builder.Run(&foreign_globals); 70 auto module = builder.Run(&foreign_globals);
71 71
72 i::MaybeHandle<i::FixedArray> compiled = 72 i::MaybeHandle<i::FixedArray> compiled =
73 CompileModule(info->isolate(), module->begin(), module->end(), &thrower, 73 CompileModule(info->isolate(), module->begin(), module->end(), &thrower,
74 internal::wasm::kAsmJsOrigin); 74 internal::wasm::kAsmJsOrigin);
75 DCHECK(!compiled.is_null()); 75 DCHECK(!compiled.is_null());
76 76
77 Handle<FixedArray> result = info->isolate()->factory()->NewFixedArray(2); 77 wasm::AsmTyper::StdlibSet uses = typer.StdlibUses();
78 Handle<FixedArray> uses_array =
79 info->isolate()->factory()->NewFixedArray(static_cast<int>(uses.size()));
80 int count = 0;
81 for (auto i : uses) {
82 uses_array->set(count++, Smi::FromInt(i));
83 }
84
85 Handle<FixedArray> result = info->isolate()->factory()->NewFixedArray(3);
78 result->set(0, *compiled.ToHandleChecked()); 86 result->set(0, *compiled.ToHandleChecked());
79 result->set(1, *foreign_globals); 87 result->set(1, *foreign_globals);
88 result->set(2, *uses_array);
80 return result; 89 return result;
81 } 90 }
82 91
92 bool AsmJs::IsStdlibValid(i::Isolate* isolate, Handle<FixedArray> wasm_data,
93 Handle<JSReceiver> stdlib) {
94 i::Handle<i::FixedArray> uses(i::FixedArray::cast(wasm_data->get(2)));
95 for (int i = 0; i < uses->length(); ++i) {
96 int32_t kind;
97 if (!uses->get(i)->ToInt32(&kind)) {
98 continue;
99 }
100 switch (kind) {
101 case wasm::AsmTyper::StandardMember::kNaN: {
102 i::Handle<i::Name> name(isolate->factory()->InternalizeOneByteString(
103 STATIC_CHAR_VECTOR("NaN")));
104 i::MaybeHandle<i::Object> maybe_value =
105 i::Object::GetProperty(stdlib, name);
106 if (maybe_value.is_null()) {
107 return false;
108 }
109 i::Handle<i::Object> value = maybe_value.ToHandleChecked();
110 if (!value->IsNaN()) {
111 return false;
112 }
titzer 2016/08/19 10:00:28 Do you want to return true here and then false for
bradn 2016/08/19 17:29:08 Actually not, because this needs to loop to check
113 } break;
114
115 default: {
116 // TODO(bradnelson): Implement check for the others
117 }
118 }
119 }
120 return true;
121 }
122
83 MaybeHandle<Object> AsmJs::InstantiateAsmWasm(i::Isolate* isolate, 123 MaybeHandle<Object> AsmJs::InstantiateAsmWasm(i::Isolate* isolate,
84 Handle<FixedArray> wasm_data, 124 Handle<FixedArray> wasm_data,
85 Handle<JSArrayBuffer> memory, 125 Handle<JSArrayBuffer> memory,
86 Handle<JSObject> foreign) { 126 Handle<JSReceiver> foreign) {
87 i::Handle<i::FixedArray> compiled(i::FixedArray::cast(wasm_data->get(0))); 127 i::Handle<i::FixedArray> compiled(i::FixedArray::cast(wasm_data->get(0)));
88 i::Handle<i::FixedArray> foreign_globals( 128 i::Handle<i::FixedArray> foreign_globals(
89 i::FixedArray::cast(wasm_data->get(1))); 129 i::FixedArray::cast(wasm_data->get(1)));
90 130
91 ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation"); 131 ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation");
92 132
93 i::MaybeHandle<i::JSObject> maybe_module_object = 133 i::MaybeHandle<i::JSObject> maybe_module_object =
94 i::wasm::WasmModule::Instantiate(isolate, compiled, foreign, memory); 134 i::wasm::WasmModule::Instantiate(isolate, compiled, foreign, memory);
95 if (maybe_module_object.is_null()) { 135 if (maybe_module_object.is_null()) {
96 return MaybeHandle<Object>(); 136 return MaybeHandle<Object>();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (retval.is_null()) { 170 if (retval.is_null()) {
131 thrower.Error( 171 thrower.Error(
132 "WASM.instantiateModuleFromAsm(): foreign init function failed"); 172 "WASM.instantiateModuleFromAsm(): foreign init function failed");
133 return MaybeHandle<Object>(); 173 return MaybeHandle<Object>();
134 } 174 }
135 return maybe_module_object; 175 return maybe_module_object;
136 } 176 }
137 177
138 } // namespace internal 178 } // namespace internal
139 } // namespace v8 179 } // namespace v8
OLDNEW
« no previous file with comments | « src/asmjs/asm-js.h ('k') | src/asmjs/asm-typer.h » ('j') | src/runtime/runtime-compiler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698