You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
Working on #4964 and noticed that Buffers have inconsistencies of when arguments are thrown and when they're coerced. This is a proposal to solidify how they should be handled. It has taken care to follow existing practices by browsers in regards to generic argument handling and that of the Typed Array specification:
Requirednumeric arguments throw if undefined.
Optionalnumeric arguments are set as default if undefined.
Arguments expected to be numeric will coerce all other values.
Any double will be floored to int.
Throw for all out of range indexes (index > buffer.length || index < 0) for any read/write methods.
buffer.slice() and buffer.copy() should follow the specification for arraybuffer.slice() (with a few modification for .copy()).
As an example of how to handle this, here are a couple verification functions:
inlineuint32_tGetOptionalUintArg(Handle<Value> arg) {
int32_t val_i = arg->Int32Value();
if (val_i < 0)
returnThrowRangeError("index is less than zero");
returnstatic_cast<uint32_t>(val_i);
}
inlineuint32_tGetRequiredUintArg(Handle<Value> arg) {
if (arg->IsUndefined())
returnThrowTypeError("argument is undefined");
returnGetOptionalUintArg(arg);
}
Working on #4964 and noticed that Buffers have inconsistencies of when arguments are thrown and when they're coerced. This is a proposal to solidify how they should be handled. It has taken care to follow existing practices by browsers in regards to generic argument handling and that of the Typed Array specification:
numericarguments throw ifundefined.numericarguments are set as default ifundefined.numericwill coerce all other values.doublewill be floored toint.index > buffer.length || index < 0) for any read/write methods.buffer.slice()andbuffer.copy()should follow the specification forarraybuffer.slice()(with a few modification for.copy()).As an example of how to handle this, here are a couple verification functions: