diff --git a/js/src/asmjs/AsmJSLink.cpp b/js/src/asmjs/AsmJSLink.cpp index 1fb0e8adb03e..8e3c8815cc7e 100644 --- a/js/src/asmjs/AsmJSLink.cpp +++ b/js/src/asmjs/AsmJSLink.cpp @@ -106,17 +106,22 @@ ValidateGlobalVariable(JSContext *cx, const AsmJSModule &module, AsmJSModule::Gl switch (global.varInitKind()) { case AsmJSModule::Global::InitConstant: { - const Value &v = global.varInitConstant(); - switch (global.varInitCoercion()) { - case AsmJS_ToInt32: + const AsmJSNumLit &lit = global.varInitNumLit(); + const Value &v = lit.value(); + switch (lit.which()) { + case AsmJSNumLit::Fixnum: + case AsmJSNumLit::NegativeInt: + case AsmJSNumLit::BigUnsigned: *(int32_t *)datum = v.toInt32(); break; - case AsmJS_ToNumber: + case AsmJSNumLit::Double: *(double *)datum = v.toDouble(); break; - case AsmJS_FRound: + case AsmJSNumLit::Float: *(float *)datum = static_cast(v.toDouble()); break; + case AsmJSNumLit::OutOfRangeInt: + MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("OutOfRangeInt isn't valid in the first place"); } break; } diff --git a/js/src/asmjs/AsmJSModule.h b/js/src/asmjs/AsmJSModule.h index f89734992156..d4bcf940f202 100644 --- a/js/src/asmjs/AsmJSModule.h +++ b/js/src/asmjs/AsmJSModule.h @@ -168,10 +168,10 @@ class AsmJSModule struct { uint32_t index_; VarInitKind initKind_; - AsmJSCoercion coercion_; union { - Value constant_; // will only contain int32/double - } init; + AsmJSCoercion coercion_; + AsmJSNumLit numLit_; + } u; } var; uint32_t ffiIndex_; Scalar::Type viewType_; @@ -196,7 +196,7 @@ class AsmJSModule if (name_) MarkStringUnbarriered(trc, &name_, "asm.js global name"); JS_ASSERT_IF(pod.which_ == Variable && pod.u.var.initKind_ == InitConstant, - !pod.u.var.init.constant_.isMarkable()); + !pod.u.var.u.numLit_.value().isMarkable()); } public: @@ -212,14 +212,15 @@ class AsmJSModule JS_ASSERT(pod.which_ == Variable); return pod.u.var.initKind_; } - const Value &varInitConstant() const { + const AsmJSNumLit &varInitNumLit() const { JS_ASSERT(pod.which_ == Variable); JS_ASSERT(pod.u.var.initKind_ == InitConstant); - return pod.u.var.init.constant_; + return pod.u.var.u.numLit_; } AsmJSCoercion varInitCoercion() const { JS_ASSERT(pod.which_ == Variable); - return pod.u.var.coercion_; + JS_ASSERT(pod.u.var.initKind_ == InitImport); + return pod.u.var.u.coercion_; } PropertyName *varImportField() const { JS_ASSERT(pod.which_ == Variable); @@ -816,14 +817,13 @@ class AsmJSModule PropertyName *bufferArgumentName() const { return bufferArgumentName_; } - bool addGlobalVarInit(const Value &v, AsmJSCoercion coercion, uint32_t *globalIndex) { + bool addGlobalVarInit(const AsmJSNumLit &lit, uint32_t *globalIndex) { JS_ASSERT(!isFinishedWithModulePrologue()); if (pod.numGlobalVars_ == UINT32_MAX) return false; Global g(Global::Variable, nullptr); g.pod.u.var.initKind_ = Global::InitConstant; - g.pod.u.var.init.constant_ = v; - g.pod.u.var.coercion_ = coercion; + g.pod.u.var.u.numLit_ = lit; g.pod.u.var.index_ = *globalIndex = pod.numGlobalVars_++; return globals_.append(g); } @@ -831,7 +831,7 @@ class AsmJSModule JS_ASSERT(!isFinishedWithModulePrologue()); Global g(Global::Variable, name); g.pod.u.var.initKind_ = Global::InitImport; - g.pod.u.var.coercion_ = coercion; + g.pod.u.var.u.coercion_ = coercion; g.pod.u.var.index_ = *globalIndex = pod.numGlobalVars_++; return globals_.append(g); } diff --git a/js/src/asmjs/AsmJSValidate.cpp b/js/src/asmjs/AsmJSValidate.cpp index 0191e41bfdc0..a205e085859d 100644 --- a/js/src/asmjs/AsmJSValidate.cpp +++ b/js/src/asmjs/AsmJSValidate.cpp @@ -1350,7 +1350,7 @@ class MOZ_STACK_CLASS ModuleCompiler bool addGlobalVarInit(PropertyName *varName, const AsmJSNumLit &lit, bool isConst) { uint32_t index; VarType type = VarType::Of(lit); - if (!module_->addGlobalVarInit(lit.value(), type.toCoercion(), &index)) + if (!module_->addGlobalVarInit(lit, &index)) return false; Global::Which which = isConst ? Global::ConstantLiteral : Global::Variable;