Merge pull request #231 from bocoup/object-is

19.1.2.10 Object.is
This commit is contained in:
Brian Terlson 2015-04-21 12:19:31 -07:00
commit 6d945e2a1e
19 changed files with 455 additions and 0 deletions

View File

@ -0,0 +1,18 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(Object.is.length, 2, "The value of `Object.is.length` is `2`");
verifyNotEnumerable(Object.is, "length");
verifyConfigurable(Object.is, "length");
verifyNotWritable(Object.is, "length");

View File

@ -0,0 +1,18 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(Object.is.name, 'is', "The value of `Object.is.name` is `'is'`");
verifyNotEnumerable(Object.is, "name");
verifyNotWritable(Object.is, "name");
verifyConfigurable(Object.is, "name");

View File

@ -0,0 +1,30 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
7.2.9 SameValue(x, y)
...
8. If Type(x) is Boolean, then
a. If x and y are both true or both false,
return true; otherwise, return false.
---*/
assert.sameValue(Object.is(true, false), false, "`Object.is(true, false)` returns `false`");
assert.sameValue(Object.is(false, true), false, "`Object.is(false, true)` returns `false`");
assert.sameValue(Object.is(true, 1), false, "`Object.is(true, 1)` returns `false`");
assert.sameValue(Object.is(false, 0), false, "`Object.is(false, 0)` returns `false`");
assert.sameValue(Object.is(true, {}), false, "`Object.is(true, {})` returns `false`");
assert.sameValue(Object.is(true, undefined), false, "`Object.is(true, undefined)` returns `false`");
assert.sameValue(Object.is(false, undefined), false, "`Object.is(false, undefined)` returns `false`");
assert.sameValue(Object.is(true, null), false, "`Object.is(true, null)` returns `false`");
assert.sameValue(Object.is(false, null), false, "`Object.is(false, null)` returns `false`");
assert.sameValue(Object.is(true, NaN), false, "`Object.is(true, NaN)` returns `false`");
assert.sameValue(Object.is(false, NaN), false, "`Object.is(false, NaN)` returns `false`");
assert.sameValue(Object.is(true, ''), false, "`Object.is(true, '')` returns `false`");
assert.sameValue(Object.is(false, ''), false, "`Object.is(false, '')` returns `false`");
assert.sameValue(Object.is(true, []), false, "`Object.is(true, [])` returns `false`");
assert.sameValue(Object.is(false, []), false, "`Object.is(false, [])` returns `false`");

View File

@ -0,0 +1,20 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
7.2.9 SameValue(x, y)
...
3. If Type(x) is different from Type(y), return false.
...
5. If Type(x) is Null, return true.
...
---*/
assert.sameValue(Object.is(null), false, "`Object.is(null)` returns `false`");
assert.sameValue(Object.is(null, undefined), false, "`Object.is(null, undefined)` returns `false`");

View File

@ -0,0 +1,21 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
...
6. If Type(x) is Number, then
a. If x is NaN and y is NaN, return true.
b. If x is +0 and y is -0, return false.
c. If x is -0 and y is +0, return false.
d. If x is the same Number value as y, return true.
e. Return false.
...
---*/
assert.sameValue(Object.is(+0, -0), false, "`Object.is(+0, -0)` returns `false`");
assert.sameValue(Object.is(-0, +0), false, "`Object.is(-0, +0)` returns `false`");
assert.sameValue(Object.is(0), false, "`Object.is(0)` returns `false`");
assert.sameValue(Object.is(Infinity, -Infinity), false, "`Object.is(Infinity, -Infinity)` returns `false`");

View File

@ -0,0 +1,32 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
...
10. Return true if x and y are the same Object value. Otherwise, return false.
---*/
assert.sameValue(Object.is({}, {}), false, "`Object.is({}, {})` returns `false`");
assert.sameValue(
Object.is(Object(), Object()),
false,
"`Object.is(Object(), Object())` returns `false`"
);
assert.sameValue(
Object.is(new Object(), new Object()),
false,
"`Object.is(new Object(), new Object())` returns `false`"
);
assert.sameValue(
Object.is(Object(0), Object(0)),
false,
"`Object.is(Object(0), Object(0))` returns `false`"
);
assert.sameValue(
Object.is(new Object(''), new Object('')),
false,
"`Object.is(new Object(''), new Object(''))` returns `false`"
);

View File

@ -0,0 +1,27 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
7.2.9 SameValue(x, y)
...
7. If Type(x) is String, then
a. If x and y are exactly the same sequence of code units
(same length and same code units at corresponding indices)
return true; otherwise, return false.
...
---*/
assert.sameValue(Object.is('', true), false, "`Object.is('', true)` returns `false`");
assert.sameValue(Object.is('', 0), false, "`Object.is('', 0)` returns `false`");
assert.sameValue(Object.is('', {}), false, "`Object.is('', {})` returns `false`");
assert.sameValue(
Object.is('', undefined),
false,
"`Object.is('', undefined)` returns `false`"
);
assert.sameValue(Object.is('', null), false, "`Object.is('', null)` returns `false`");
assert.sameValue(Object.is('', NaN), false, "`Object.is('', NaN)` returns `false`");

View File

@ -0,0 +1,24 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
...
6. If Type(x) is Symbol, then
a. If x and y are both the same Symbol value,
return true; otherwise, return false.
...
---*/
assert.sameValue(
Object.is(Symbol(), Symbol()),
false,
"`Object.is(Symbol(), Symbol())` returns `false`"
);
assert.sameValue(
Object.is(Symbol('description'), Symbol('description')),
false,
"`Object.is(Symbol('description'), Symbol('description'))` returns `false`"
);

View File

@ -0,0 +1,69 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
7.2.9 SameValue(x, y)
...
3. If Type(x) is different from Type(y), return false.
...
---*/
var a = {};
assert.sameValue(Object.is(a, true), false, "`Object.is(a, true)` returns `false`");
assert.sameValue(Object.is(a, ''), false, "`Object.is(a, '')` returns `false`");
assert.sameValue(Object.is(a, 0), false, "`Object.is(a, 0)` returns `false`");
assert.sameValue(
Object.is(a, undefined),
false,
"`Object.is(a, undefined)` returns `false`"
);
assert.sameValue(Object.is(NaN, true), false, "`Object.is(NaN, true)` returns `false`");
assert.sameValue(Object.is(NaN, ''), false, "`Object.is(NaN, '')` returns `false`");
assert.sameValue(Object.is(NaN, a), false, "`Object.is(NaN, a)` returns `false`");
assert.sameValue(
Object.is(NaN, undefined),
false,
"`Object.is(NaN, undefined)` returns `false`"
);
assert.sameValue(Object.is(NaN, null), false, "`Object.is(NaN, null)` returns `false`");
assert.sameValue(Object.is(true, 0), false, "`Object.is(true, 0)` returns `false`");
assert.sameValue(Object.is(true, a), false, "`Object.is(true, a)` returns `false`");
assert.sameValue(
Object.is(true, undefined),
false,
"`Object.is(true, undefined)` returns `false`"
);
assert.sameValue(Object.is(true, null), false, "`Object.is(true, null)` returns `false`");
assert.sameValue(Object.is(true, NaN), false, "`Object.is(true, NaN)` returns `false`");
assert.sameValue(Object.is(true, ''), false, "`Object.is(true, '')` returns `false`");
assert.sameValue(Object.is(false, 0), false, "`Object.is(false, 0)` returns `false`");
assert.sameValue(Object.is(false, a), false, "`Object.is(false, a)` returns `false`");
assert.sameValue(
Object.is(false, undefined),
false,
"`Object.is(false, undefined)` returns `false`"
);
assert.sameValue(Object.is(false, null), false, "`Object.is(false, null)` returns `false`");
assert.sameValue(Object.is(false, NaN), false, "`Object.is(false, NaN)` returns `false`");
assert.sameValue(Object.is(false, ''), false, "`Object.is(false, '')` returns `false`");
assert.sameValue(Object.is(0, true), false, "`Object.is(0, true)` returns `false`");
assert.sameValue(Object.is(0, a), false, "`Object.is(0, a)` returns `false`");
assert.sameValue(
Object.is(0, undefined),
false,
"`Object.is(0, undefined)` returns `false`"
);
assert.sameValue(Object.is(0, null), false, "`Object.is(0, null)` returns `false`");
assert.sameValue(Object.is(0, NaN), false, "`Object.is(0, NaN)` returns `false`");
assert.sameValue(Object.is(0, ''), false, "`Object.is(0, '')` returns `false`");

View File

@ -0,0 +1,16 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
7.2.9 SameValue(x, y)
...
4. If Type(x) is Undefined, return true.
...
---*/
assert.sameValue(Object.is(undefined, null), false, "`Object.is(undefined, null)` returns `false`");

View File

@ -0,0 +1,19 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(typeof Object.is, "function");
assert.sameValue(Object.is.name, "is");
verifyWritable(Object, "is");
verifyNotEnumerable(Object, "is");
verifyConfigurable(Object, "is");

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
7.2.9 SameValue(x, y)
...
8. If Type(x) is Boolean, then
a. If x and y are both true or both false,
return true; otherwise, return false.
---*/
assert.sameValue(Object.is(true, true), true, "`Object.is(true, true)` returns `true`");
assert.sameValue(Object.is(false, false), true, "`Object.is(false, false)` returns `true`");

View File

@ -0,0 +1,16 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
7.2.9 SameValue(x, y)
...
4. If Type(x) is Undefined, return true.
...
---*/
assert.sameValue(Object.is(), true, "`Object.is()` returns `true`");

View File

@ -0,0 +1,19 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
7.2.9 SameValue(x, y)
...
3. If Type(x) is different from Type(y), return false.
...
5. If Type(x) is Null, return true.
...
---*/
assert.sameValue(Object.is(null, null), true, "`Object.is(null, null)` returns `true`");

View File

@ -0,0 +1,21 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
...
6. If Type(x) is Number, then
a. If x is NaN and y is NaN, return true.
b. If x is +0 and y is -0, return false.
c. If x is -0 and y is +0, return false.
d. If x is the same Number value as y, return true.
e. Return false.
...
---*/
assert.sameValue(Object.is(NaN, NaN), true, "`Object.is(NaN, NaN)` returns `true`");
assert.sameValue(Object.is(-0, -0), true, "`Object.is(-0, -0)` returns `true`");
assert.sameValue(Object.is(+0, +0), true, "`Object.is(+0, +0)` returns `true`");
assert.sameValue(Object.is(0, 0), true, "`Object.is(0, 0)` returns `true`");

View File

@ -0,0 +1,24 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
...
10. Return true if x and y are the same Object value. Otherwise, return false.
---*/
var a = {};
var b = Object(0);
var c = new Object("");
var d = [];
var e = Array();
var f = new Array();
assert.sameValue(Object.is(a, a), true, "`Object.is(a, a)` returns `true`");
assert.sameValue(Object.is(b, b), true, "`Object.is(b, b)` returns `true`");
assert.sameValue(Object.is(c, c), true, "`Object.is(c, c)` returns `true`");
assert.sameValue(Object.is(d, d), true, "`Object.is(d, d)` returns `true`");
assert.sameValue(Object.is(e, e), true, "`Object.is(e, e)` returns `true`");
assert.sameValue(Object.is(f, f), true, "`Object.is(f, f)` returns `true`");

View File

@ -0,0 +1,28 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
7.2.9 SameValue(x, y)
...
7. If Type(x) is String, then
a. If x and y are exactly the same sequence of code units
(same length and same code units at corresponding indices)
return true; otherwise, return false.
...
---*/
assert.sameValue(Object.is('', ''), true, "`Object.is('', '')` returns `true`");
assert.sameValue(
Object.is('foo', 'foo'),
true,
"`Object.is('foo', 'foo')` returns `true`"
);
assert.sameValue(
Object.is(String('foo'), String('foo')),
true,
"`Object.is(String('foo'), String('foo'))` returns `true`"
);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
...
6. If Type(x) is Symbol, then
a. If x and y are both the same Symbol value,
return true; otherwise, return false.
...
---*/
var a = Symbol();
var b = Symbol("description");
assert.sameValue(Object.is(a, a), true, "`Object.is(a, a)` returns `true`");
assert.sameValue(Object.is(b, b), true, "`Object.is(b, b)` returns `true`");

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.2.10
description: >
Object.is ( value1, value2 )
7.2.9 SameValue(x, y)
...
4. If Type(x) is Undefined, return true.
...
---*/
assert.sameValue(Object.is(undefined, undefined), true, "`Object.is(undefined, undefined)` returns `true`");
assert.sameValue(Object.is(undefined), true, "`Object.is(undefined)` returns `true`");