Bug 1112769 - Move the contents of js/src/vm/NumericConversions.h into a new js/public/Conversions.h header containing public API. r=jorendorff

--HG--
rename : js/src/vm/NumericConversions.h => js/public/Conversions.h
extra : rebase_source : c6b30f38cbc3eafa5eb861ba578234c28982459d
This commit is contained in:
Jeff Walden 2014-12-17 13:50:14 -08:00
parent 94cf66c1f1
commit 535fe9c758
24 changed files with 76 additions and 39 deletions

View File

@ -4,17 +4,18 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef vm_NumericConversions_h
#define vm_NumericConversions_h
/* ECMAScript conversion operations. */
#ifndef js_Conversions_h
#define js_Conversions_h
#include "mozilla/Assertions.h"
#include "mozilla/Casting.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/TypeTraits.h"
#include <math.h>
namespace js {
namespace JS {
namespace detail {
@ -124,7 +125,7 @@ ToIntWidth(double d)
return (MinValue + static_cast<ResultType>(u - MaxValue)) - 1;
}
} /* namespace detail */
} // namespace detail
/* ES5 9.5 ToInt32 (specialized for doubles). */
inline int32_t
@ -293,6 +294,6 @@ ToInteger(double d)
return d < 0 ? ceil(d) : floor(d);
}
} /* namespace js */
} // namespace JS
#endif /* vm_NumericConversions_h */
#endif /* js_Conversions_h */

View File

@ -37,6 +37,7 @@
#include "frontend/Parser.h"
#include "jit/IonCode.h"
#include "js/Conversions.h"
#include "js/MemoryMetrics.h"
#include "jsobjinlines.h"
@ -671,7 +672,7 @@ AddressOf(AsmJSImmKind kind, ExclusiveContext *cx)
case AsmJSImm_CoerceInPlace_ToNumber:
return RedirectCall(FuncCast(CoerceInPlace_ToNumber), Args_General1);
case AsmJSImm_ToInt32:
return RedirectCall(FuncCast<int32_t (double)>(js::ToInt32), Args_Int_Double);
return RedirectCall(FuncCast<int32_t (double)>(JS::ToInt32), Args_Int_Double);
#if defined(JS_CODEGEN_ARM)
case AsmJSImm_aeabi_idivmod:
return RedirectCall(FuncCast(__aeabi_idivmod), Args_General2);

View File

@ -9,7 +9,9 @@
#include "jsapi.h"
#include "jsobj.h"
#include "builtin/TypedObject.h"
#include "js/Conversions.h"
#include "vm/GlobalObject.h"
/*
@ -219,7 +221,7 @@ struct Int32x4 {
return global.int32x4TypeDescr().as<TypeDescr>();
}
static Elem toType(Elem a) {
return ToInt32(a);
return JS::ToInt32(a);
}
static bool toType(JSContext *cx, JS::HandleValue v, Elem *out) {
return ToInt32(cx, v, out);

View File

@ -11,6 +11,7 @@
#include "jsweakmap.h"
#include "builtin/TypedObjectConstants.h"
#include "js/Conversions.h"
#include "vm/ArrayBufferObject.h"
/*
@ -104,10 +105,10 @@ static T ConvertScalar(double d)
if (TypeIsFloatingPoint<T>()) {
return T(d);
} else if (TypeIsUnsigned<T>()) {
uint32_t n = ToUint32(d);
uint32_t n = JS::ToUint32(d);
return T(n);
} else {
int32_t n = ToInt32(d);
int32_t n = JS::ToInt32(d);
return T(n);
}
}

View File

@ -13,7 +13,7 @@
#include "frontend/ParseNode.h"
#include "frontend/Parser.h"
#include "vm/NumericConversions.h"
#include "js/Conversions.h"
#include "jscntxtinlines.h"
#include "jsinferinlines.h"
@ -27,6 +27,8 @@ using mozilla::IsNegative;
using mozilla::NegativeInfinity;
using mozilla::PositiveInfinity;
using JS::GenericNaN;
using JS::ToInt32;
using JS::ToUint32;
static bool
ContainsVarOrConst(ExclusiveContext *cx, ParseNode *pn, ParseNode **resultp)

View File

@ -6,6 +6,7 @@
#include "jit/BaselineIC.h"
#include "mozilla/Casting.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/TemplateLib.h"
@ -23,6 +24,7 @@
# include "jit/PerfSpewer.h"
#endif
#include "jit/VMFunctions.h"
#include "js/Conversions.h"
#include "vm/Opcodes.h"
#include "vm/TypedArrayCommon.h"
@ -34,6 +36,7 @@
#include "vm/ScopeObject-inl.h"
#include "vm/StringObject-inl.h"
using mozilla::BitwiseCast;
using mozilla::DebugOnly;
namespace js {
@ -3053,7 +3056,7 @@ ICBinaryArith_DoubleWithInt32::Compiler::generateStubCode(MacroAssembler &masm)
masm.push(intReg);
masm.setupUnalignedABICall(1, scratchReg);
masm.passABIArg(FloatReg0, MoveOp::DOUBLE);
masm.callWithABI(JS_FUNC_TO_DATA_PTR(void *, js::ToInt32));
masm.callWithABI(mozilla::BitwiseCast<void*, int32_t(*)(double)>(JS::ToInt32));
masm.storeCallResult(scratchReg);
masm.pop(intReg);
@ -3202,7 +3205,7 @@ ICUnaryArith_Double::Compiler::generateStubCode(MacroAssembler &masm)
masm.bind(&truncateABICall);
masm.setupUnalignedABICall(1, scratchReg);
masm.passABIArg(FloatReg0, MoveOp::DOUBLE);
masm.callWithABI(JS_FUNC_TO_DATA_PTR(void *, js::ToInt32));
masm.callWithABI(BitwiseCast<void*, int32_t(*)(double)>(JS::ToInt32));
masm.storeCallResult(scratchReg);
masm.bind(&doneTruncate);

View File

@ -19,6 +19,7 @@
#include "jit/JitSpewer.h"
#include "jit/MIRGraph.h"
#include "jit/RangeAnalysis.h"
#include "js/Conversions.h"
#include "jsatominlines.h"
#include "jsinferinlines.h"
@ -27,6 +28,8 @@
using namespace js;
using namespace js::jit;
using JS::ToInt32;
using mozilla::NumbersAreIdentical;
using mozilla::IsFloat32Representable;
using mozilla::Maybe;

View File

@ -19,6 +19,7 @@
#include "jit/Lowering.h"
#include "jit/MIR.h"
#include "jit/ParallelFunctions.h"
#include "js/Conversions.h"
#include "vm/ForkJoin.h"
#include "vm/TraceLogging.h"
@ -31,6 +32,7 @@ using namespace js;
using namespace js::jit;
using JS::GenericNaN;
using JS::ToInt32;
namespace {
@ -2099,7 +2101,7 @@ MacroAssembler::convertValueToInt(JSContext *cx, const Value &v, Register output
break;
}
case IntConversion_Truncate:
move32(Imm32(js::ToInt32(d)), output);
move32(Imm32(ToInt32(d)), output);
break;
case IntConversion_ClampToUint8:
move32(Imm32(ClampDoubleToUint8(d)), output);

View File

@ -14,7 +14,7 @@
#include "jit/MIR.h"
#include "jit/MIRGenerator.h"
#include "jit/MIRGraph.h"
#include "vm/NumericConversions.h"
#include "js/Conversions.h"
#include "vm/TypedArrayCommon.h"
#include "jsopcodeinlines.h"
@ -35,6 +35,7 @@ using mozilla::NegativeInfinity;
using mozilla::PositiveInfinity;
using mozilla::Swap;
using JS::GenericNaN;
using JS::ToInt32;
// This algorithm is based on the paper "Eliminating Range Checks Using
// Static Single Assignment Form" by Gough and Klaren.

View File

@ -16,6 +16,7 @@
#include "jit/MIR.h"
#include "jit/MIRGenerator.h"
#include "jit/ParallelFunctions.h"
#include "js/Conversions.h"
#include "vm/TraceLogging.h"
#include "jit/JitFrames-inl.h"
@ -23,6 +24,7 @@
using namespace js;
using namespace js::jit;
using mozilla::BitwiseCast;
using mozilla::DebugOnly;
namespace js {
@ -1146,7 +1148,7 @@ CodeGeneratorShared::visitOutOfLineTruncateSlow(OutOfLineTruncateSlow *ool)
if (gen->compilingAsmJS())
masm.callWithABI(AsmJSImm_ToInt32);
else
masm.callWithABI(JS_FUNC_TO_DATA_PTR(void *, js::ToInt32));
masm.callWithABI(BitwiseCast<void*, int32_t(*)(double)>(JS::ToInt32));
masm.storeCallResult(dest);
#ifndef JS_CODEGEN_ARM

View File

@ -7,11 +7,12 @@
#include <math.h>
#include "jsapi-tests/tests.h"
#include "vm/NumericConversions.h"
#include "js/Conversions.h"
using js::detail::ToIntWidth;
using js::detail::ToUintWidth;
#include "jsapi-tests/tests.h"
using JS::detail::ToIntWidth;
using JS::detail::ToUintWidth;
BEGIN_TEST(testToUint8TwiceUint8Range)
{

View File

@ -61,6 +61,7 @@
#include "gc/Marking.h"
#include "jit/JitCommon.h"
#include "js/CharacterEncoding.h"
#include "js/Conversions.h"
#include "js/SliceBudget.h"
#include "js/StructuredClone.h"
#if ENABLE_INTL_API
@ -72,7 +73,6 @@
#include "vm/ErrorObject.h"
#include "vm/HelperThreads.h"
#include "vm/Interpreter.h"
#include "vm/NumericConversions.h"
#include "vm/RegExpStatics.h"
#include "vm/Runtime.h"
#include "vm/SavedStacks.h"
@ -105,6 +105,9 @@ using mozilla::PodZero;
using mozilla::UniquePtr;
using JS::AutoGCRooter;
using JS::ToInt32;
using JS::ToInteger;
using JS::ToUint32;
using js::frontend::Parser;

View File

@ -26,10 +26,10 @@
#include "ds/Sort.h"
#include "gc/Heap.h"
#include "js/Conversions.h"
#include "vm/ArgumentsObject.h"
#include "vm/ForkJoin.h"
#include "vm/Interpreter.h"
#include "vm/NumericConversions.h"
#include "vm/Shape.h"
#include "vm/StringBuffer.h"
#include "vm/TypedArrayCommon.h"
@ -53,6 +53,7 @@ using mozilla::DebugOnly;
using mozilla::IsNaN;
using JS::AutoCheckCannotGC;
using JS::ToUint32;
bool
js::GetLengthProperty(JSContext *cx, HandleObject obj, uint32_t *lengthp)

View File

@ -35,11 +35,11 @@
#include "jswrapper.h"
#include "prmjtime.h"
#include "js/Conversions.h"
#include "js/Date.h"
#include "vm/DateTime.h"
#include "vm/GlobalObject.h"
#include "vm/Interpreter.h"
#include "vm/NumericConversions.h"
#include "vm/String.h"
#include "vm/StringBuffer.h"
@ -54,6 +54,7 @@ using mozilla::IsNaN;
using JS::AutoCheckCannotGC;
using JS::GenericNaN;
using JS::ToInteger;
/*
* The JS 'Date' object is patterned after the Java 'Date' object.

View File

@ -28,8 +28,8 @@
#include "jsstr.h"
#include "jstypes.h"
#include "js/Conversions.h"
#include "vm/GlobalObject.h"
#include "vm/NumericConversions.h"
#include "vm/StringBuffer.h"
#include "jsatominlines.h"
@ -51,6 +51,10 @@ using mozilla::RangedPtr;
using JS::AutoCheckCannotGC;
using JS::GenericNaN;
using JS::ToInt32;
using JS::ToInt64;
using JS::ToUint32;
using JS::ToUint64;
/*
* If we're accumulating a decimal number and the number is >= 2^53, then the
@ -1022,7 +1026,7 @@ Number_isInteger(JSContext *cx, unsigned argc, Value *vp)
Value val = args[0];
args.rval().setBoolean(val.isInt32() ||
(mozilla::IsFinite(val.toDouble()) &&
ToInteger(val.toDouble()) == val.toDouble()));
JS::ToInteger(val.toDouble()) == val.toDouble()));
return true;
}
@ -1720,7 +1724,7 @@ js::ToLengthClamped(T *cx, HandleValue v, uint32_t *out, bool *overflow)
return false;
}
}
d = ToInteger(d);
d = JS::ToInteger(d);
if (d <= 0.0) {
*out = 0;
return true;

View File

@ -12,7 +12,7 @@
#include "NamespaceImports.h"
#include "vm/NumericConversions.h"
#include "js/Conversions.h"
namespace js {
@ -246,7 +246,7 @@ ToInteger(JSContext *cx, HandleValue v, double *dp)
if (!ToNumberSlow(cx, v, dp))
return false;
}
*dp = ToInteger(*dp);
*dp = JS::ToInteger(*dp);
return true;
}

View File

@ -32,12 +32,12 @@
#include "builtin/Intl.h"
#include "builtin/RegExp.h"
#include "js/Conversions.h"
#if ENABLE_INTL_API
#include "unicode/unorm.h"
#endif
#include "vm/GlobalObject.h"
#include "vm/Interpreter.h"
#include "vm/NumericConversions.h"
#include "vm/Opcodes.h"
#include "vm/RegExpObject.h"
#include "vm/RegExpStatics.h"
@ -57,6 +57,8 @@ using namespace js::unicode;
using JS::Symbol;
using JS::SymbolCode;
using JS::ToInt32;
using JS::ToUint32;
using mozilla::AssertedCast;
using mozilla::CheckedInt;
@ -1662,7 +1664,7 @@ js::str_lastIndexOf(JSContext *cx, unsigned argc, Value *vp)
if (!ToNumber(cx, args[1], &d))
return false;
if (!IsNaN(d)) {
d = ToInteger(d);
d = JS::ToInteger(d);
if (d <= 0)
start = 0;
else if (d < start)

View File

@ -67,6 +67,7 @@ EXPORTS.js += [
'../public/CallNonGenericMethod.h',
'../public/CharacterEncoding.h',
'../public/Class.h',
'../public/Conversions.h',
'../public/Date.h',
'../public/Debug.h',
'../public/GCAPI.h',

View File

@ -38,10 +38,10 @@
#include "gc/Barrier.h"
#include "gc/Marking.h"
#include "gc/Memory.h"
#include "js/Conversions.h"
#include "js/MemoryMetrics.h"
#include "vm/GlobalObject.h"
#include "vm/Interpreter.h"
#include "vm/NumericConversions.h"
#include "vm/WrapperObject.h"
#include "jsatominlines.h"
@ -51,6 +51,8 @@
#include "vm/NativeObject-inl.h"
#include "vm/Shape-inl.h"
using JS::ToInt32;
using mozilla::DebugOnly;
using mozilla::UniquePtr;

View File

@ -12,8 +12,8 @@
#include <stdint.h>
#include "js/Conversions.h"
#include "js/Value.h"
#include "vm/NumericConversions.h"
namespace js {
@ -50,7 +50,7 @@ TimeClip(double time)
return JS::GenericNaN();
/* Step 3. */
return ToInteger(time + (+0.0));
return JS::ToInteger(time + (+0.0));
}
/*

View File

@ -21,7 +21,6 @@
#include "gc/Heap.h"
#include "gc/Marking.h"
#include "js/Value.h"
#include "vm/NumericConversions.h"
#include "vm/Shape.h"
#include "vm/String.h"

View File

@ -31,10 +31,10 @@
#include "asmjs/AsmJSValidate.h"
#include "gc/Barrier.h"
#include "gc/Marking.h"
#include "js/Conversions.h"
#include "vm/ArrayBufferObject.h"
#include "vm/GlobalObject.h"
#include "vm/Interpreter.h"
#include "vm/NumericConversions.h"
#include "vm/SharedArrayObject.h"
#include "vm/TypedArrayCommon.h"
#include "vm/WrapperObject.h"
@ -55,6 +55,8 @@ using mozilla::PodCopy;
using mozilla::PositiveInfinity;
using JS::CanonicalizeNaN;
using JS::GenericNaN;
using JS::ToInt32;
using JS::ToUint32;
TypedArrayLayout SharedTypedArrayObject::layout_(true, // shared
false, // neuterable

View File

@ -13,6 +13,7 @@
#include "mozilla/FloatingPoint.h"
#include "mozilla/PodOperations.h"
#include "js/Conversions.h"
#include "js/Value.h"
#include "vm/SharedTypedArrayObject.h"
@ -444,8 +445,8 @@ class ElementSpecific
if (MOZ_UNLIKELY(mozilla::IsNaN(d)))
return T(0);
if (TypeIsUnsigned<T>())
return T(ToUint32(d));
return T(ToInt32(d));
return T(JS::ToUint32(d));
return T(JS::ToInt32(d));
}
};

View File

@ -31,10 +31,10 @@
#include "builtin/TypedObjectConstants.h"
#include "gc/Barrier.h"
#include "gc/Marking.h"
#include "js/Conversions.h"
#include "vm/ArrayBufferObject.h"
#include "vm/GlobalObject.h"
#include "vm/Interpreter.h"
#include "vm/NumericConversions.h"
#include "vm/TypedArrayCommon.h"
#include "vm/WrapperObject.h"
@ -55,6 +55,8 @@ using mozilla::PodCopy;
using mozilla::PositiveInfinity;
using JS::CanonicalizeNaN;
using JS::GenericNaN;
using JS::ToInt32;
using JS::ToUint32;
/*
* TypedArrayObject