Chromium Code Reviews| Index: src/asmjs/asm-js.cc |
| diff --git a/src/asmjs/asm-js.cc b/src/asmjs/asm-js.cc |
| index c38c0537358b1f5f38606c05af9efcc568fedb2a..fa9ed598cb94c0b3f63524a1deff495a244245f7 100644 |
| --- a/src/asmjs/asm-js.cc |
| +++ b/src/asmjs/asm-js.cc |
| @@ -62,10 +62,29 @@ bool IsStdlibMemberValid(i::Isolate* isolate, Handle<JSReceiver> stdlib, |
| switch (member_kind) { |
| case wasm::AsmTyper::StandardMember::kNone: |
| case wasm::AsmTyper::StandardMember::kModule: |
| - case wasm::AsmTyper::StandardMember::kStdlib: { |
| + case wasm::AsmTyper::StandardMember::kStdlib: |
| + case wasm::AsmTyper::StandardMember::kHeap: |
| + case wasm::AsmTyper::StandardMember::kFFI: { |
| // Nothing to check for these. |
| return true; |
| } |
| + case wasm::AsmTyper::StandardMember::kInfinity: { |
| + i::Handle<i::Name> name(isolate->factory()->InternalizeOneByteString( |
| + STATIC_CHAR_VECTOR("Infinity"))); |
| + 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->IsNumber()) { |
| + return false; |
| + } |
| + if (!std::isinf(value->Number())) { |
| + return false; |
| + } |
| + return true; |
| + } |
| case wasm::AsmTyper::StandardMember::kNaN: { |
| i::Handle<i::Name> name(isolate->factory()->InternalizeOneByteString( |
| STATIC_CHAR_VECTOR("NaN"))); |
| @@ -80,38 +99,95 @@ bool IsStdlibMemberValid(i::Isolate* isolate, Handle<JSReceiver> stdlib, |
| } |
| return true; |
| } |
| - case wasm::AsmTyper::StandardMember::kHeap: |
| - case wasm::AsmTyper::StandardMember::kFFI: |
| - case wasm::AsmTyper::StandardMember::kInfinity: |
| - case wasm::AsmTyper::StandardMember::kMathAcos: |
| - case wasm::AsmTyper::StandardMember::kMathAsin: |
| - case wasm::AsmTyper::StandardMember::kMathAtan: |
| - case wasm::AsmTyper::StandardMember::kMathCos: |
| - case wasm::AsmTyper::StandardMember::kMathSin: |
| - case wasm::AsmTyper::StandardMember::kMathTan: |
| - case wasm::AsmTyper::StandardMember::kMathExp: |
| - case wasm::AsmTyper::StandardMember::kMathLog: |
| - case wasm::AsmTyper::StandardMember::kMathCeil: |
| - case wasm::AsmTyper::StandardMember::kMathFloor: |
| - case wasm::AsmTyper::StandardMember::kMathSqrt: |
| - case wasm::AsmTyper::StandardMember::kMathAbs: |
| - case wasm::AsmTyper::StandardMember::kMathClz32: |
| - case wasm::AsmTyper::StandardMember::kMathMin: |
| - case wasm::AsmTyper::StandardMember::kMathMax: |
| - case wasm::AsmTyper::StandardMember::kMathAtan2: |
| - case wasm::AsmTyper::StandardMember::kMathPow: |
| - case wasm::AsmTyper::StandardMember::kMathImul: |
| - case wasm::AsmTyper::StandardMember::kMathFround: |
| - case wasm::AsmTyper::StandardMember::kMathE: |
| - case wasm::AsmTyper::StandardMember::kMathLN10: |
| - case wasm::AsmTyper::StandardMember::kMathLN2: |
| - case wasm::AsmTyper::StandardMember::kMathLOG2E: |
| - case wasm::AsmTyper::StandardMember::kMathLOG10E: |
| - case wasm::AsmTyper::StandardMember::kMathPI: |
| - case wasm::AsmTyper::StandardMember::kMathSQRT1_2: |
| - case wasm::AsmTyper::StandardMember::kMathSQRT2: |
| - // TODO(bradnelson) Actually check these. |
| - return true; |
| +#define STDLIB_MATH_FUNC(CamelName, fname) \ |
|
titzer
2016/08/22 08:41:22
That's a pretty big macro. Can you factor some of
bradn
2016/08/22 16:53:40
Good idea.
Done.
|
| + case wasm::AsmTyper::StandardMember::k##CamelName: { \ |
| + i::Handle<i::Name> math_name(isolate->factory()->InternalizeOneByteString( \ |
| + STATIC_CHAR_VECTOR("Math"))); \ |
| + i::MaybeHandle<i::Object> maybe_math = \ |
| + i::Object::GetProperty(stdlib, math_name); \ |
| + if (maybe_math.is_null()) { \ |
| + return false; \ |
| + } \ |
| + i::Handle<i::Object> math = maybe_math.ToHandleChecked(); \ |
| + if (!math->IsJSReceiver()) { \ |
| + return false; \ |
| + } \ |
| + i::Handle<i::Name> name(isolate->factory()->InternalizeOneByteString( \ |
| + STATIC_CHAR_VECTOR(#fname))); \ |
| + i::MaybeHandle<i::Object> maybe_value = \ |
| + i::Object::GetProperty(math, name); \ |
| + if (maybe_value.is_null()) { \ |
| + return false; \ |
| + } \ |
| + i::Handle<i::Object> value = maybe_value.ToHandleChecked(); \ |
| + if (!value->IsJSFunction()) { \ |
| + return false; \ |
| + } \ |
| + i::Handle<i::JSFunction> func(i::JSFunction::cast(*value)); \ |
| + if (func->shared()->code() != \ |
| + isolate->builtins()->builtin(Builtins::k##CamelName)) { \ |
| + return false; \ |
| + } \ |
| + return true; \ |
| + } |
| + STDLIB_MATH_FUNC(MathAcos, acos) |
| + STDLIB_MATH_FUNC(MathAsin, asin) |
| + STDLIB_MATH_FUNC(MathAtan, atan) |
| + STDLIB_MATH_FUNC(MathCos, cos) |
| + STDLIB_MATH_FUNC(MathSin, sin) |
| + STDLIB_MATH_FUNC(MathTan, tan) |
| + STDLIB_MATH_FUNC(MathExp, exp) |
| + STDLIB_MATH_FUNC(MathLog, log) |
| + STDLIB_MATH_FUNC(MathCeil, ceil) |
| + STDLIB_MATH_FUNC(MathFloor, floor) |
| + STDLIB_MATH_FUNC(MathSqrt, sqrt) |
| + STDLIB_MATH_FUNC(MathAbs, abs) |
| + STDLIB_MATH_FUNC(MathClz32, clz32) |
| + STDLIB_MATH_FUNC(MathMin, min) |
| + STDLIB_MATH_FUNC(MathMax, max) |
| + STDLIB_MATH_FUNC(MathAtan2, atan2) |
| + STDLIB_MATH_FUNC(MathPow, pow) |
| + STDLIB_MATH_FUNC(MathImul, imul) |
| + STDLIB_MATH_FUNC(MathFround, fround) |
| +#undef STDLIB_MATH_FUNC |
| +#define STDLIB_MATH_CONST(cname, const_value) \ |
| + case wasm::AsmTyper::StandardMember::kMath##cname: { \ |
| + i::Handle<i::Name> math_name(isolate->factory()->InternalizeOneByteString( \ |
| + STATIC_CHAR_VECTOR("Math"))); \ |
| + i::MaybeHandle<i::Object> maybe_math = \ |
| + i::Object::GetProperty(stdlib, math_name); \ |
| + if (maybe_math.is_null()) { \ |
| + return false; \ |
| + } \ |
| + i::Handle<i::Object> math = maybe_math.ToHandleChecked(); \ |
| + if (!math->IsJSReceiver()) { \ |
| + return false; \ |
| + } \ |
| + i::Handle<i::Name> name(isolate->factory()->InternalizeOneByteString( \ |
| + STATIC_CHAR_VECTOR(#cname))); \ |
| + i::MaybeHandle<i::Object> maybe_value = \ |
| + i::Object::GetProperty(math, name); \ |
| + if (maybe_value.is_null()) { \ |
| + return false; \ |
| + } \ |
| + i::Handle<i::Object> value = maybe_value.ToHandleChecked(); \ |
| + if (!value->IsNumber()) { \ |
| + return false; \ |
| + } \ |
| + if (value->Number() != const_value) { \ |
| + return false; \ |
| + } \ |
| + return true; \ |
| + } |
| + STDLIB_MATH_CONST(E, 2.718281828459045) |
| + STDLIB_MATH_CONST(LN10, 2.302585092994046) |
| + STDLIB_MATH_CONST(LN2, 0.6931471805599453) |
| + STDLIB_MATH_CONST(LOG2E, 1.4426950408889634) |
| + STDLIB_MATH_CONST(LOG10E, 0.4342944819032518) |
| + STDLIB_MATH_CONST(PI, 3.141592653589793) |
| + STDLIB_MATH_CONST(SQRT1_2, 0.7071067811865476) |
| + STDLIB_MATH_CONST(SQRT2, 1.4142135623730951) |
| +#undef STDLIB_MATH_CONST |
| default: { UNREACHABLE(); } |
| } |
| return false; |