зеркало из https://github.com/mozilla/gecko-dev.git
Bug 839979 - Implement Object.is. r=jorendorff
This commit is contained in:
Родитель
e21bd39ae2
Коммит
e39915f6c6
|
@ -791,6 +791,20 @@ obj_keys(JSContext *cx, unsigned argc, Value *vp)
|
|||
return true;
|
||||
}
|
||||
|
||||
/* ES6 draft 15.2.3.16 */
|
||||
static JSBool
|
||||
obj_is(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
bool same;
|
||||
if (!SameValue(cx, args.get(0), args.get(1), &same))
|
||||
return false;
|
||||
|
||||
args.rval().setBoolean(same);
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
obj_getOwnPropertyNames(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
|
@ -982,6 +996,7 @@ JSFunctionSpec js::object_static_methods[] = {
|
|||
JS_FN("getPrototypeOf", obj_getPrototypeOf, 1,0),
|
||||
JS_FN("getOwnPropertyDescriptor", obj_getOwnPropertyDescriptor,2,0),
|
||||
JS_FN("keys", obj_keys, 1,0),
|
||||
JS_FN("is", obj_is, 2,0),
|
||||
JS_FN("defineProperty", obj_defineProperty, 3,0),
|
||||
JS_FN("defineProperties", obj_defineProperties, 2,0),
|
||||
JS_FN("create", obj_create, 2,0),
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/
|
||||
*/
|
||||
|
||||
var list = [
|
||||
[1, 1, true],
|
||||
[0, 1, false],
|
||||
[3.5, 3.5, true],
|
||||
[0, 0, true],
|
||||
[0, -0, false],
|
||||
[-0, 0, false],
|
||||
[-0, -0, true],
|
||||
|
||||
[true, true, true],
|
||||
[true, false, false],
|
||||
[false, false, true],
|
||||
|
||||
[NaN, NaN, true],
|
||||
[NaN, undefined, false],
|
||||
[Infinity, -Infinity, false],
|
||||
[Infinity, Infinity, true],
|
||||
]
|
||||
|
||||
for (var test of list) {
|
||||
assertEq(Object.is(test[0], test[1]), test[2])
|
||||
}
|
||||
|
||||
var obj = {}
|
||||
assertEq(Object.is(obj, obj), true);
|
||||
assertEq(Object.is(obj, {}), false);
|
||||
assertEq(Object.is([], []), false);
|
||||
|
||||
assertEq(Object.is(null, null, null), true);
|
||||
|
||||
/* Not defined parameters are undefined ... */
|
||||
assertEq(Object.is(null), false);
|
||||
assertEq(Object.is(undefined), true);
|
||||
assertEq(Object.is(), true);
|
||||
|
||||
assertEq(Object.is.length, 2);
|
Загрузка…
Ссылка в новой задаче