Index: src/asmjs/asm-js.cc |
diff --git a/src/asmjs/asm-js.cc b/src/asmjs/asm-js.cc |
index cb44ec237a2f3c48267d1d834fb3b6a2ee4b867f..8ea367e8006cea921ada41a6f6b37f580cf1d526 100644 |
--- a/src/asmjs/asm-js.cc |
+++ b/src/asmjs/asm-js.cc |
@@ -74,16 +74,56 @@ MaybeHandle<FixedArray> AsmJs::ConvertAsmToWasm(ParseInfo* info) { |
internal::wasm::kAsmJsOrigin); |
DCHECK(!compiled.is_null()); |
- Handle<FixedArray> result = info->isolate()->factory()->NewFixedArray(2); |
+ wasm::AsmTyper::StdlibSet uses = typer.StdlibUses(); |
+ Handle<FixedArray> uses_array = |
+ info->isolate()->factory()->NewFixedArray(static_cast<int>(uses.size())); |
+ int count = 0; |
+ for (auto i : uses) { |
+ uses_array->set(count++, Smi::FromInt(i)); |
+ } |
+ |
+ Handle<FixedArray> result = info->isolate()->factory()->NewFixedArray(3); |
result->set(0, *compiled.ToHandleChecked()); |
result->set(1, *foreign_globals); |
+ result->set(2, *uses_array); |
return result; |
} |
+bool AsmJs::IsStdlibValid(i::Isolate* isolate, Handle<FixedArray> wasm_data, |
+ Handle<JSReceiver> stdlib) { |
+ i::Handle<i::FixedArray> uses(i::FixedArray::cast(wasm_data->get(2))); |
+ for (int i = 0; i < uses->length(); ++i) { |
+ int32_t kind; |
+ if (!uses->get(i)->ToInt32(&kind)) { |
+ continue; |
+ } |
+ switch (kind) { |
+ case wasm::AsmTyper::StandardMember::kNaN: { |
+ i::Handle<i::Name> name(isolate->factory()->InternalizeOneByteString( |
+ STATIC_CHAR_VECTOR("NaN"))); |
+ i::MaybeHandle<i::Object> maybe_value = |
+ i::Object::GetProperty(stdlib, name); |
+ if (maybe_value.is_null()) { |
+ return false; |
+ } |
+ i::Handle<i::Object> value = maybe_value.ToHandleChecked(); |
+ if (!value->IsNaN()) { |
+ return false; |
+ } |
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
|
+ } break; |
+ |
+ default: { |
+ // TODO(bradnelson): Implement check for the others |
+ } |
+ } |
+ } |
+ return true; |
+} |
+ |
MaybeHandle<Object> AsmJs::InstantiateAsmWasm(i::Isolate* isolate, |
Handle<FixedArray> wasm_data, |
Handle<JSArrayBuffer> memory, |
- Handle<JSObject> foreign) { |
+ Handle<JSReceiver> foreign) { |
i::Handle<i::FixedArray> compiled(i::FixedArray::cast(wasm_data->get(0))); |
i::Handle<i::FixedArray> foreign_globals( |
i::FixedArray::cast(wasm_data->get(1))); |