зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1536695 - Part 2: Support infallible conversion for BigInt types. r=jandem
Differential Revision: https://phabricator.services.mozilla.com/D26119 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
ab632c5202
Коммит
95a26641c7
|
@ -24,6 +24,7 @@
|
||||||
#include "jit/AtomicOperations.h"
|
#include "jit/AtomicOperations.h"
|
||||||
#include "js/Conversions.h"
|
#include "js/Conversions.h"
|
||||||
#include "js/Value.h"
|
#include "js/Value.h"
|
||||||
|
#include "vm/BigIntType.h"
|
||||||
#include "vm/JSContext.h"
|
#include "vm/JSContext.h"
|
||||||
#include "vm/NativeObject.h"
|
#include "vm/NativeObject.h"
|
||||||
|
|
||||||
|
@ -644,12 +645,28 @@ class ElementSpecific {
|
||||||
static bool canConvertInfallibly(const Value& v) {
|
static bool canConvertInfallibly(const Value& v) {
|
||||||
if (TypeIDOfType<T>::id == Scalar::BigInt64 ||
|
if (TypeIDOfType<T>::id == Scalar::BigInt64 ||
|
||||||
TypeIDOfType<T>::id == Scalar::BigUint64) {
|
TypeIDOfType<T>::id == Scalar::BigUint64) {
|
||||||
return false;
|
// Numbers, Null, Undefined, and Symbols throw a TypeError. Strings may
|
||||||
|
// OOM and Objects may have side-effects.
|
||||||
|
return v.isBigInt() || v.isBoolean();
|
||||||
}
|
}
|
||||||
|
// BigInts and Symbols throw a TypeError. Strings may OOM and Objects may
|
||||||
|
// have side-effects.
|
||||||
return v.isNumber() || v.isBoolean() || v.isNull() || v.isUndefined();
|
return v.isNumber() || v.isBoolean() || v.isNull() || v.isUndefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
static T infallibleValueToNative(const Value& v) {
|
static T infallibleValueToNative(const Value& v) {
|
||||||
|
if (TypeIDOfType<T>::id == Scalar::BigInt64) {
|
||||||
|
if (v.isBigInt()) {
|
||||||
|
return T(BigInt::toInt64(v.toBigInt()));
|
||||||
|
}
|
||||||
|
return T(v.toBoolean());
|
||||||
|
}
|
||||||
|
if (TypeIDOfType<T>::id == Scalar::BigUint64) {
|
||||||
|
if (v.isBigInt()) {
|
||||||
|
return T(BigInt::toUint64(v.toBigInt()));
|
||||||
|
}
|
||||||
|
return T(v.toBoolean());
|
||||||
|
}
|
||||||
if (v.isInt32()) {
|
if (v.isInt32()) {
|
||||||
return T(v.toInt32());
|
return T(v.toInt32());
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче