зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1528582 - Add DataView methods for BigInt access r=wingo,jwalden
Differential Revision: https://phabricator.services.mozilla.com/D20081 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
7f14366c55
Коммит
73b54fd50c
|
@ -313,6 +313,14 @@ struct DataToRepType<uint32_t> {
|
|||
typedef uint32_t result;
|
||||
};
|
||||
template <>
|
||||
struct DataToRepType<int64_t> {
|
||||
typedef uint64_t result;
|
||||
};
|
||||
template <>
|
||||
struct DataToRepType<uint64_t> {
|
||||
typedef uint64_t result;
|
||||
};
|
||||
template <>
|
||||
struct DataToRepType<float> {
|
||||
typedef uint32_t result;
|
||||
};
|
||||
|
@ -418,6 +426,28 @@ static inline bool WebIDLCast(JSContext* cx, HandleValue value,
|
|||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool WebIDLCast<int64_t>(JSContext* cx, HandleValue value,
|
||||
int64_t* out) {
|
||||
RootedBigInt bi(cx, ToBigInt(cx, value));
|
||||
if (!bi) {
|
||||
return false;
|
||||
}
|
||||
*out = BigInt::toInt64(bi);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool WebIDLCast<uint64_t>(JSContext* cx, HandleValue value,
|
||||
uint64_t* out) {
|
||||
RootedBigInt bi(cx, ToBigInt(cx, value));
|
||||
if (!bi) {
|
||||
return false;
|
||||
}
|
||||
*out = BigInt::toUint64(bi);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool WebIDLCast<float>(JSContext* cx, HandleValue value, float* out) {
|
||||
double temp;
|
||||
|
@ -433,6 +463,8 @@ inline bool WebIDLCast<double>(JSContext* cx, HandleValue value, double* out) {
|
|||
return ToNumber(cx, value, out);
|
||||
}
|
||||
|
||||
// https://tc39.github.io/ecma262/#sec-setviewvalue
|
||||
// SetViewValue ( view, requestIndex, isLittleEndian, type, value )
|
||||
template <typename NativeType>
|
||||
/* static */ bool DataViewObject::write(JSContext* cx,
|
||||
Handle<DataViewObject*> obj,
|
||||
|
@ -446,7 +478,7 @@ template <typename NativeType>
|
|||
return false;
|
||||
}
|
||||
|
||||
// Step 5. Should just call ToNumber (unobservable)
|
||||
// Step 5. Extended by the BigInt proposal to call either ToBigInt or ToNumber
|
||||
NativeType value;
|
||||
if (!WebIDLCast(cx, args.get(1), &value)) {
|
||||
return false;
|
||||
|
@ -602,6 +634,58 @@ bool DataViewObject::fun_getUint32(JSContext* cx, unsigned argc, Value* vp) {
|
|||
return CallNonGenericMethod<is, getUint32Impl>(cx, args);
|
||||
}
|
||||
|
||||
// BigInt proposal 7.26
|
||||
// DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] )
|
||||
bool DataViewObject::getBigInt64Impl(JSContext* cx, const CallArgs& args) {
|
||||
MOZ_ASSERT(is(args.thisv()));
|
||||
|
||||
Rooted<DataViewObject*> thisView(
|
||||
cx, &args.thisv().toObject().as<DataViewObject>());
|
||||
|
||||
int64_t val;
|
||||
if (!read(cx, thisView, args, &val)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BigInt* bi = BigInt::createFromInt64(cx, val);
|
||||
if (!bi) {
|
||||
return false;
|
||||
}
|
||||
args.rval().setBigInt(bi);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataViewObject::fun_getBigInt64(JSContext* cx, unsigned argc, Value* vp) {
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
return CallNonGenericMethod<is, getBigInt64Impl>(cx, args);
|
||||
}
|
||||
|
||||
// BigInt proposal 7.27
|
||||
// DataView.prototype.getBigUint64 ( byteOffset [ , littleEndian ] )
|
||||
bool DataViewObject::getBigUint64Impl(JSContext* cx, const CallArgs& args) {
|
||||
MOZ_ASSERT(is(args.thisv()));
|
||||
|
||||
Rooted<DataViewObject*> thisView(
|
||||
cx, &args.thisv().toObject().as<DataViewObject>());
|
||||
|
||||
int64_t val;
|
||||
if (!read(cx, thisView, args, &val)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BigInt* bi = BigInt::createFromUint64(cx, val);
|
||||
if (!bi) {
|
||||
return false;
|
||||
}
|
||||
args.rval().setBigInt(bi);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataViewObject::fun_getBigUint64(JSContext* cx, unsigned argc, Value* vp) {
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
return CallNonGenericMethod<is, getBigUint64Impl>(cx, args);
|
||||
}
|
||||
|
||||
bool DataViewObject::getFloat32Impl(JSContext* cx, const CallArgs& args) {
|
||||
MOZ_ASSERT(is(args.thisv()));
|
||||
|
||||
|
@ -750,6 +834,46 @@ bool DataViewObject::fun_setUint32(JSContext* cx, unsigned argc, Value* vp) {
|
|||
return CallNonGenericMethod<is, setUint32Impl>(cx, args);
|
||||
}
|
||||
|
||||
// BigInt proposal 7.28
|
||||
// DataView.prototype.setBigInt64 ( byteOffset, value [ , littleEndian ] )
|
||||
bool DataViewObject::setBigInt64Impl(JSContext* cx, const CallArgs& args) {
|
||||
MOZ_ASSERT(is(args.thisv()));
|
||||
|
||||
Rooted<DataViewObject*> thisView(
|
||||
cx, &args.thisv().toObject().as<DataViewObject>());
|
||||
|
||||
if (!write<int64_t>(cx, thisView, args)) {
|
||||
return false;
|
||||
}
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataViewObject::fun_setBigInt64(JSContext* cx, unsigned argc, Value* vp) {
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
return CallNonGenericMethod<is, setBigInt64Impl>(cx, args);
|
||||
}
|
||||
|
||||
// BigInt proposal 7.29
|
||||
// DataView.prototype.setBigUint64 ( byteOffset, value [ , littleEndian ] )
|
||||
bool DataViewObject::setBigUint64Impl(JSContext* cx, const CallArgs& args) {
|
||||
MOZ_ASSERT(is(args.thisv()));
|
||||
|
||||
Rooted<DataViewObject*> thisView(
|
||||
cx, &args.thisv().toObject().as<DataViewObject>());
|
||||
|
||||
if (!write<uint64_t>(cx, thisView, args)) {
|
||||
return false;
|
||||
}
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataViewObject::fun_setBigUint64(JSContext* cx, unsigned argc, Value* vp) {
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
return CallNonGenericMethod<is, setBigUint64Impl>(cx, args);
|
||||
}
|
||||
|
||||
bool DataViewObject::setFloat32Impl(JSContext* cx, const CallArgs& args) {
|
||||
MOZ_ASSERT(is(args.thisv()));
|
||||
|
||||
|
@ -845,6 +969,15 @@ JSObject* DataViewObject::CreatePrototype(JSContext* cx, JSProtoKey key) {
|
|||
&DataViewObject::protoClass_);
|
||||
}
|
||||
|
||||
// Add extra methods for BigInt if its run-time option is enabled.
|
||||
bool DataViewObject::finishInit(JSContext* cx, JS::HandleObject ctor,
|
||||
JS::HandleObject proto) {
|
||||
if (cx->realm()->creationOptions().getBigIntEnabled()) {
|
||||
return JS_DefineFunctions(cx, proto, bigIntMethods);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static const ClassOps DataViewObjectClassOps = {nullptr, /* addProperty */
|
||||
nullptr, /* delProperty */
|
||||
nullptr, /* enumerate */
|
||||
|
@ -865,6 +998,7 @@ const ClassSpec DataViewObject::classSpec_ = {
|
|||
nullptr,
|
||||
DataViewObject::methods,
|
||||
DataViewObject::properties,
|
||||
DataViewObject::finishInit
|
||||
};
|
||||
|
||||
const Class DataViewObject::class_ = {
|
||||
|
@ -897,6 +1031,13 @@ const JSFunctionSpec DataViewObject::methods[] = {
|
|||
JS_FN("setFloat64", DataViewObject::fun_setFloat64, 2, 0),
|
||||
JS_FS_END};
|
||||
|
||||
const JSFunctionSpec DataViewObject::bigIntMethods[] = {
|
||||
JS_FN("getBigInt64", DataViewObject::fun_getBigInt64, 1, 0),
|
||||
JS_FN("getBigUint64", DataViewObject::fun_getBigUint64, 1, 0),
|
||||
JS_FN("setBigInt64", DataViewObject::fun_setBigInt64, 2, 0),
|
||||
JS_FN("setBigUint64", DataViewObject::fun_setBigUint64, 2, 0),
|
||||
JS_FS_END};
|
||||
|
||||
const JSPropertySpec DataViewObject::properties[] = {
|
||||
JS_PSG("buffer", DataViewObject::bufferGetter, 0),
|
||||
JS_PSG("byteLength", DataViewObject::byteLengthGetter, 0),
|
||||
|
|
|
@ -101,6 +101,12 @@ class DataViewObject : public ArrayBufferViewObject {
|
|||
static bool getUint32Impl(JSContext* cx, const CallArgs& args);
|
||||
static bool fun_getUint32(JSContext* cx, unsigned argc, Value* vp);
|
||||
|
||||
static bool getBigInt64Impl(JSContext* cx, const CallArgs& args);
|
||||
static bool fun_getBigInt64(JSContext* cx, unsigned argc, Value* vp);
|
||||
|
||||
static bool getBigUint64Impl(JSContext* cx, const CallArgs& args);
|
||||
static bool fun_getBigUint64(JSContext* cx, unsigned argc, Value* vp);
|
||||
|
||||
static bool getFloat32Impl(JSContext* cx, const CallArgs& args);
|
||||
static bool fun_getFloat32(JSContext* cx, unsigned argc, Value* vp);
|
||||
|
||||
|
@ -125,6 +131,12 @@ class DataViewObject : public ArrayBufferViewObject {
|
|||
static bool setUint32Impl(JSContext* cx, const CallArgs& args);
|
||||
static bool fun_setUint32(JSContext* cx, unsigned argc, Value* vp);
|
||||
|
||||
static bool setBigInt64Impl(JSContext* cx, const CallArgs& args);
|
||||
static bool fun_setBigInt64(JSContext* cx, unsigned argc, Value* vp);
|
||||
|
||||
static bool setBigUint64Impl(JSContext* cx, const CallArgs& args);
|
||||
static bool fun_setBigUint64(JSContext* cx, unsigned argc, Value* vp);
|
||||
|
||||
static bool setFloat32Impl(JSContext* cx, const CallArgs& args);
|
||||
static bool fun_setFloat32(JSContext* cx, unsigned argc, Value* vp);
|
||||
|
||||
|
@ -141,6 +153,10 @@ class DataViewObject : public ArrayBufferViewObject {
|
|||
private:
|
||||
static const JSFunctionSpec methods[];
|
||||
static const JSPropertySpec properties[];
|
||||
|
||||
static const JSFunctionSpec bigIntMethods[];
|
||||
static bool finishInit(JSContext* cx, JS::HandleObject ctor,
|
||||
JS::HandleObject proto);
|
||||
};
|
||||
|
||||
} // namespace js
|
||||
|
|
|
@ -918,48 +918,6 @@ skip script test262/built-ins/TypedArrayConstructors/prototype/copyWithin/bigint
|
|||
skip script test262/built-ins/TypedArrayConstructors/prototype/map/bigint-inherited.js
|
||||
skip script test262/built-ins/TypedArrayConstructors/prototype/set/bigint-inherited.js
|
||||
skip script test262/built-ins/TypedArrayConstructors/prototype/sort/bigint-inherited.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigInt64/negative-byteoffset-throws.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigInt64/return-value-clean-arraybuffer.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigInt64/return-values-custom-offset.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigInt64/name.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-after-toindex-byteoffset.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-errors.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigInt64/to-boolean-littleendian.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigInt64/length.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-toprimitive.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigInt64/return-values.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigInt64/index-is-out-of-range.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-wrapped-values.js
|
||||
skip script test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value.js
|
||||
skip script test262/built-ins/DataView/prototype/setBigInt64/index-check-before-value-conversion.js
|
||||
skip script test262/built-ins/DataView/prototype/setBigInt64/negative-byteoffset-throws.js
|
||||
skip script test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset.js
|
||||
skip script test262/built-ins/DataView/prototype/setBigInt64/set-values-little-endian-order.js
|
||||
skip script test262/built-ins/DataView/prototype/setBigInt64/name.js
|
||||
skip script test262/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-toindex-byteoffset.js
|
||||
skip script test262/built-ins/DataView/prototype/setBigInt64/set-values-return-undefined.js
|
||||
skip script test262/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-bigint-value.js
|
||||
skip script test262/built-ins/DataView/prototype/setBigInt64/to-boolean-littleendian.js
|
||||
skip script test262/built-ins/DataView/prototype/setBigInt64/toindex-byteoffset.js
|
||||
skip script test262/built-ins/DataView/prototype/setBigInt64/length.js
|
||||
skip script test262/built-ins/DataView/prototype/setBigInt64/index-is-out-of-range.js
|
||||
skip script test262/built-ins/DataView/prototype/setBigInt64/range-check-after-value-conversion.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigUint64/negative-byteoffset-throws.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigUint64/return-value-clean-arraybuffer.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigUint64/return-abrupt-from-tonumber-byteoffset.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigUint64/return-values-custom-offset.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigUint64/name.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigUint64/detached-buffer-after-toindex-byteoffset.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-errors.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigUint64/to-boolean-littleendian.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigUint64/length.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-toprimitive.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigUint64/return-values.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigUint64/index-is-out-of-range.js
|
||||
skip script test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-wrapped-values.js
|
||||
|
||||
# https://bugzilla.mozilla.org/show_bug.cgi?id=1317405
|
||||
skip script test262/language/computed-property-names/class/static/method-number.js
|
||||
|
|
Загрузка…
Ссылка в новой задаче