From 511ce3b2c170d37e0b18894e8540c2b341683818 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Tue, 17 Oct 2017 13:09:15 -0400 Subject: [PATCH] typeof ... fixups --- test/language/expressions/typeof/bigint.js | 45 +++++++++- test/language/expressions/typeof/boolean.js | 29 ++++--- .../typeof/built-in-exotic-objects-no-call.js | 75 ++++++++++++++++ .../expressions/typeof/built-in-functions.js | 29 +++++-- .../built-in-ordinary-objects-no-call.js | 31 +++++++ .../expressions/typeof/get-value-ref-err.js | 25 ++++++ test/language/expressions/typeof/get-value.js | 45 ++++++---- .../expressions/typeof/native-call.js | 41 +++++---- .../expressions/typeof/native-no-call.js | 86 ------------------- test/language/expressions/typeof/null.js | 22 +++-- test/language/expressions/typeof/number.js | 28 ++++-- test/language/expressions/typeof/string.js | 30 ++++--- test/language/expressions/typeof/symbol.js | 47 +++++++--- test/language/expressions/typeof/undefined.js | 21 +++-- .../typeof/unresolvable-reference.js | 20 +++-- 15 files changed, 388 insertions(+), 186 deletions(-) create mode 100644 test/language/expressions/typeof/built-in-exotic-objects-no-call.js create mode 100644 test/language/expressions/typeof/built-in-ordinary-objects-no-call.js create mode 100644 test/language/expressions/typeof/get-value-ref-err.js delete mode 100644 test/language/expressions/typeof/native-no-call.js diff --git a/test/language/expressions/typeof/bigint.js b/test/language/expressions/typeof/bigint.js index 4bf70988e0..d8bda8b9ac 100644 --- a/test/language/expressions/typeof/bigint.js +++ b/test/language/expressions/typeof/bigint.js @@ -3,13 +3,50 @@ /*--- esid: sec-typeof-operator-runtime-semantics-evaluation -description: typeof of BigInt and BigInt object -info: > +description: typeof BigInt literal and BigInt object +info: | The typeof Operator Runtime Semantics: Evaluation + + ... + Return a String according to Table 35. + + #table-35 + + BigInt "bigint" + Object(BigInt()) "object" + features: [BigInt] ---*/ -assert.sameValue(typeof 0n, "bigint"); -assert.sameValue(typeof Object(0n), "object"); +assert.sameValue( + typeof 0n, + "bigint", + "typeof 0n === 'bigint'" +); +assert.sameValue( + typeof BigInt(0n), + "bigint", + "typeof BigInt(0n) === 'bigint'" +); +assert.sameValue( + typeof BigInt(0), + "bigint", + "typeof BigInt(0) === 'bigint'" +); +assert.sameValue( + typeof Object(BigInt(0n)), + "object", + "typeof Object(BigInt(0n)) === 'object'" +); +assert.sameValue( + typeof Object(BigInt(0)), + "object", + "typeof Object(BigInt(0)) === 'object'" +); +assert.sameValue( + typeof Object(0n), + "object", + "typeof Object(0n) === 'object'" +); diff --git a/test/language/expressions/typeof/boolean.js b/test/language/expressions/typeof/boolean.js index 5e5f184b10..93e9a4e8b9 100644 --- a/test/language/expressions/typeof/boolean.js +++ b/test/language/expressions/typeof/boolean.js @@ -2,26 +2,31 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -info: Result of applying "typeof" operator to boolean is "boolean" -es5id: 11.4.3_A3.3 -es6id: 12.5.6.1 -description: typeof (boolean value) === "boolean" +esid: sec-typeof-operator-runtime-semantics-evaluation +description: typeof Boolean literal +info: | + The typeof Operator + + Runtime Semantics: Evaluation + + ... + Return a String according to Table 35. + + #table-35 + + Boolean "boolean" + + ---*/ assert.sameValue( typeof true, "boolean", - '#1: typeof true === "boolean". Actual: ' + (typeof true) + 'typeof true === "boolean"' ); assert.sameValue( typeof false, "boolean", - '#2: typeof false === "boolean". Actual: ' + (typeof false) -); - -assert.sameValue( - typeof !-1, - "boolean", - '#3: typeof !-1 === "boolean". Actual: ' + (typeof !-1) + 'typeof false === "boolean"' ); diff --git a/test/language/expressions/typeof/built-in-exotic-objects-no-call.js b/test/language/expressions/typeof/built-in-exotic-objects-no-call.js new file mode 100644 index 0000000000..0aab119170 --- /dev/null +++ b/test/language/expressions/typeof/built-in-exotic-objects-no-call.js @@ -0,0 +1,75 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typeof-operator-runtime-semantics-evaluation +description: typeof Object (standard exotic and does not implement [[Call]]) === "object" +info: | + The typeof Operator + + Runtime Semantics: Evaluation + + ... + Return a String according to Table 35. + + #table-35 + + Object (standard exotic and does not implement [[Call]]) "object" + + +---*/ + +assert.sameValue( + typeof this, + "object", + 'typeof this === "object"' +); + +assert.sameValue( + typeof new Object(), + "object", + 'typeof new Object() === "object"' +); + +assert.sameValue( + typeof new Array(), + "object", + 'typeof new Array() === "object"' +); + +assert.sameValue( + typeof new String(), + "object", + 'typeof new String() === "object"' +); + +assert.sameValue( + typeof new Boolean(), + "object", + 'typeof new Boolean() === "object"' +); + +assert.sameValue( + typeof new Number(), + "object", + 'typeof new Number() === "object"' +); + +assert.sameValue( + typeof new Date(), + "object", + 'typeof new Date() === "object"' +); + +assert.sameValue( + typeof new Error(), + "object", + ' typeof new Error() === "object"' +); + +assert.sameValue( + typeof new RegExp(), + "object", + ' typeof new RegExp() === "object"' +); + diff --git a/test/language/expressions/typeof/built-in-functions.js b/test/language/expressions/typeof/built-in-functions.js index 2e0dcc2d6c..d20450ed8c 100644 --- a/test/language/expressions/typeof/built-in-functions.js +++ b/test/language/expressions/typeof/built-in-functions.js @@ -2,22 +2,35 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -info: > - There are two types of Function objects. Internal functions - are built-in objects of the language, such as parseInt and Math.exp -es5id: 10.1.1_A2_T1 -es6id: 12.5.6.1 -description: Checking types of parseInt and Math.exp +esid: sec-typeof-operator-runtime-semantics-evaluation +description: typeof Object (implements [[Call]]) === "function" +info: | + The typeof Operator + + Runtime Semantics: Evaluation + + ... + Return a String according to Table 35. + + #table-35 + + Object (implements [[Call]]) "function" + + + ---*/ assert.sameValue( typeof Math.exp, "function", - '#1: typeof Math.exp!=="function" '+typeof Math.exp + 'typeof Math.exp === "function"' ); assert.sameValue( typeof parseInt, "function", - '#2: typeof parseInt!=="function" '+typeof parseInt + 'typeof parseInt === "function"' ); + +// TODO: should this be expanded to check all built-ins? +// that might be excessive... diff --git a/test/language/expressions/typeof/built-in-ordinary-objects-no-call.js b/test/language/expressions/typeof/built-in-ordinary-objects-no-call.js new file mode 100644 index 0000000000..2f7c18b62c --- /dev/null +++ b/test/language/expressions/typeof/built-in-ordinary-objects-no-call.js @@ -0,0 +1,31 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typeof-operator-runtime-semantics-evaluation +description: typeof Object (ordinary and does not implement [[Call]]) === "object" +info: | + The typeof Operator + + Runtime Semantics: Evaluation + + ... + Return a String according to Table 35. + + #table-35 + + Object (ordinary and does not implement [[Call]]) "object" + +---*/ + +assert.sameValue( + typeof Math, + "object", + 'typeof Math === "object"' +); + +assert.sameValue( + typeof Reflect, + "object", + 'typeof Reflect === "object"' +); diff --git a/test/language/expressions/typeof/get-value-ref-err.js b/test/language/expressions/typeof/get-value-ref-err.js new file mode 100644 index 0000000000..49ddecb379 --- /dev/null +++ b/test/language/expressions/typeof/get-value-ref-err.js @@ -0,0 +1,25 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typeof-operator-runtime-semantics-evaluation +description: Operator "typeof" uses GetValue +info: | + The typeof Operator + + Runtime Semantics: Evaluation + + ... + Set val to ? GetValue(val). + ... + + GetValue ( V ): + + ... + If IsUnresolvableReference(V) is true, throw a ReferenceError exception. + +---*/ + +assert.throws(ReferenceError, function() { + typeof x.x; +}); diff --git a/test/language/expressions/typeof/get-value.js b/test/language/expressions/typeof/get-value.js index 2e52c0caa1..8b53e91d85 100644 --- a/test/language/expressions/typeof/get-value.js +++ b/test/language/expressions/typeof/get-value.js @@ -2,28 +2,43 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -info: Operator "typeof" uses GetValue -es5id: 11.4.3_A2_T1 -es6id: 12.5.6.1 -description: Either Type(x) is not Reference or GetBase(x) is not null +esid: sec-typeof-operator-runtime-semantics-evaluation +description: Operator "typeof" uses GetValue +info: | + The typeof Operator + + Runtime Semantics: Evaluation + + ... + Set val to ? GetValue(val). + ... + ---*/ -assert.sameValue( - typeof 0, - "number", - '#1: typeof 0 === "number". Actual: ' + (typeof 0) -); +var count = 0; + +Object.defineProperties(this, { + x: { + value: 1 + }, + y: { + get() { + count++; + return 1; + } + } +}); -var x = 0; assert.sameValue( typeof x, "number", - '#2: typeof x === "number". Actual: ' + (typeof x) + 'typeof x === "number"' ); -var x = new Object(); assert.sameValue( - typeof x, - "object", - '#3: var x = new Object(); typeof x === "object". Actual: ' + (typeof x) + typeof y, + "number", + 'typeof y === "number"' ); + +assert.sameValue(count, 1); diff --git a/test/language/expressions/typeof/native-call.js b/test/language/expressions/typeof/native-call.js index a4508e8798..1d192bec88 100644 --- a/test/language/expressions/typeof/native-call.js +++ b/test/language/expressions/typeof/native-call.js @@ -2,64 +2,75 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -info: > - Result of applying "typeof" operator to the object that is native and - implements [[Call]] is "function" -es5id: 11.4.3_A3.7 -es6id: 12.5.6.1 -description: typeof (object with [[Call]]) === "function" +esid: sec-typeof-operator-runtime-semantics-evaluation +description: typeof Object (implements [[Call]]) === "function" +info: | + The typeof Operator + + Runtime Semantics: Evaluation + + ... + Return a String according to Table 35. + + #table-35 + + Object (implements [[Call]]) "function" + + ---*/ assert.sameValue( typeof new Function(), "function", - '#1: typeof new Function() === "function". Actual: ' + (typeof new Function()) + 'typeof new Function() === "function"' ); assert.sameValue( typeof Function(), "function", - '#2: typeof Function() === "function". Actual: ' + (typeof Function()) + 'typeof Function() === "function"' ); assert.sameValue( typeof Object, "function", - '#3: typeof Object === "function". Actual: ' + (typeof Object) + 'typeof Object === "function"' ); assert.sameValue( typeof String, "function", - '#4: typeof String === "function". Actual: ' + (typeof String) + 'typeof String === "function"' ); assert.sameValue( typeof Boolean, "function", - '#5: typeof Boolean === "function". Actual: ' + (typeof Boolean) + 'typeof Boolean === "function"' ); assert.sameValue( typeof Number, "function", - '#6: typeof Number === "function". Actual: ' + (typeof Number) + 'typeof Number === "function"' ); assert.sameValue( typeof Date, "function", - '#7: typeof Date === "function". Actual: ' + (typeof Date) + 'typeof Date === "function"' ); assert.sameValue( typeof Error, "function", - '#8: typeof Error === "function". Actual: ' + (typeof Error) + 'typeof Error === "function"' ); assert.sameValue( typeof RegExp, "function", - '#9: typeof RegExp === "function". Actual: ' + (typeof RegExp) + 'typeof RegExp === "function"' ); + +// TODO: Should this be extended to include all built-ins? diff --git a/test/language/expressions/typeof/native-no-call.js b/test/language/expressions/typeof/native-no-call.js deleted file mode 100644 index 54401573c3..0000000000 --- a/test/language/expressions/typeof/native-no-call.js +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: > - Result of applying "typeof" operator to the object that is native and - doesn't implement [[Call]] is "object" -es5id: 11.4.3_A3.6 -es6id: 12.5.6.1 -description: typeof (object without [[Call]]) === "object" ----*/ - -assert.sameValue( - typeof this, - "object", - '#1: typeof this === "object". Actual: ' + (typeof this) -); - -assert.sameValue( - typeof new Object(), - "object", - '#2: typeof new Object() === "object". Actual: ' + (typeof new Object()) -); - -assert.sameValue( - typeof new Array(1,2,3), - "object", - '#3: typeof new Array(1,2,3) === "object". Actual: ' + (typeof new Array(1,2,3)) -); - -assert.sameValue( - typeof Array(1,2,3), - "object", - '#4: typeof Array(1,2,3) === "object". Actual: ' + (typeof Array(1,2,3)) -); - -assert.sameValue( - typeof new String("x"), - "object", - '#5: typeof new String("x") === "object". Actual: ' + (typeof new String("x")) -); - -assert.sameValue( - typeof new Boolean(true), - "object", - '#6: typeof new Boolean(true) === "object". Actual: ' + (typeof new Boolean(true)) -); - -assert.sameValue( - typeof new Number(1), - "object", - '#7: typeof new Number(1) === "object". Actual: ' + (typeof new Number(1)) -); - -//The Math object does not have a [[Construct]] property; -//it is not possible to use the Math object as a constructor with the new operator. -//The Math object does not have a [[Call]] property; it is not possible to invoke the Math object as a object. -assert.sameValue( - typeof Math, - "object", - '#8: typeof Math === "object". Actual: ' + (typeof Math) -); - -assert.sameValue( - typeof new Date(), - "object", - '#9: typeof new Date() === "object". Actual: ' + (typeof new Date()) -); - -assert.sameValue( - typeof new Error(), - "object", - '#10: typeof new Error() === "object". Actual: ' + (typeof new Error()) -); - -assert.sameValue( - typeof new RegExp(), - "object", - '#11: typeof new RegExp() === "object". Actual: ' + (typeof new RegExp()) -); - -assert.sameValue( - typeof RegExp(), - "object", - '#12: typeof RegExp() === "object". Actual: ' + (typeof RegExp()) -); diff --git a/test/language/expressions/typeof/null.js b/test/language/expressions/typeof/null.js index 9f81ea1470..67214a4c4b 100644 --- a/test/language/expressions/typeof/null.js +++ b/test/language/expressions/typeof/null.js @@ -2,20 +2,30 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -info: Result of applying "typeof" operator to null is "object" -es5id: 11.4.3_A3.2 -es6id: 12.5.6.1 -description: typeof null === "object" +esid: sec-typeof-operator-runtime-semantics-evaluation +description: typeof Object (implements [[Call]]) === "function" +info: | + The typeof Operator + + Runtime Semantics: Evaluation + + ... + Return a String according to Table 35. + + #table-35 + + Null "object" + ---*/ assert.sameValue( typeof null, "object", - '#1: typeof null === "object". Actual: ' + (typeof null) + 'typeof null === "object"' ); assert.sameValue( typeof RegExp("0").exec("1"), "object", - '#2: typeof RegExp("0").exec("1") === "object". Actual: ' + (typeof RegExp("0").exec("1")) + 'typeof RegExp("0").exec("1") === "object"' ); diff --git a/test/language/expressions/typeof/number.js b/test/language/expressions/typeof/number.js index bc1f87cecf..eae0a394ae 100644 --- a/test/language/expressions/typeof/number.js +++ b/test/language/expressions/typeof/number.js @@ -2,38 +2,48 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -info: Result of appying "typeof" operator to number is "number" -es5id: 11.4.3_A3.4 -es6id: 12.5.6.1 -description: typeof (number value) === "number" +esid: sec-typeof-operator-runtime-semantics-evaluation +description: typeof Number literal +info: | + The typeof Operator + + Runtime Semantics: Evaluation + + ... + Return a String according to Table 35. + + #table-35 + + Number "number" + ---*/ assert.sameValue( typeof 1, "number", - 'typeof 1 === "number". Actual: ' + (typeof 1) + 'typeof 1 === "number"' ); assert.sameValue( typeof NaN, "number", - 'typeof NaN === "number". Actual: ' + (typeof NaN) + 'typeof NaN === "number"' ); assert.sameValue( typeof Infinity, "number", - 'typeof Infinity === "number". Actual: ' + (typeof Infinity) + 'typeof Infinity === "number"' ); assert.sameValue( typeof -Infinity, "number", - 'typeof -Infinity === "number". Actual: ' + (typeof -Infinity) + 'typeof -Infinity === "number"' ); assert.sameValue( typeof Math.PI, "number", - 'typeof Math.PI === "number". Actual: ' + (typeof Math.PI) + 'typeof Math.PI === "number"' ); diff --git a/test/language/expressions/typeof/string.js b/test/language/expressions/typeof/string.js index c5c5fbd045..3278e25777 100644 --- a/test/language/expressions/typeof/string.js +++ b/test/language/expressions/typeof/string.js @@ -2,44 +2,54 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -info: Result of appying "typeof" operator to string is "string" -es5id: 11.4.3_A3.5 -es6id: 12.5.6.1 -description: typeof (string value) === "string" +esid: sec-typeof-operator-runtime-semantics-evaluation +description: typeof String literal +info: | + The typeof Operator + + Runtime Semantics: Evaluation + + ... + Return a String according to Table 35. + + #table-35 + + String "string" + ---*/ assert.sameValue( typeof "1", "string", - '#1: typeof "1" === "string". Actual: ' + (typeof "1") + 'typeof "1" === "string"' ); assert.sameValue( typeof "NaN", "string", - '#2: typeof "NaN" === "string". Actual: ' + (typeof "NaN") + 'typeof "NaN" === "string"' ); assert.sameValue( typeof "Infinity", "string", - '#3: typeof "Infinity" === "string". Actual: ' + (typeof "Infinity") + 'typeof "Infinity" === "string"' ); assert.sameValue( typeof "", "string", - '#4: typeof "" === "string". Actual: ' + (typeof "") + 'typeof "" === "string"' ); assert.sameValue( typeof "true", "string", - '#5: typeof "true" === "string". Actual: ' + (typeof "true") + 'typeof "true" === "string"' ); assert.sameValue( typeof Date(), "string", - '#6: typeof Date() === "string". Actual: ' + (typeof Date()) + 'typeof Date() === "string"' ); diff --git a/test/language/expressions/typeof/symbol.js b/test/language/expressions/typeof/symbol.js index 93e8a1ca9a..0e09813508 100644 --- a/test/language/expressions/typeof/symbol.js +++ b/test/language/expressions/typeof/symbol.js @@ -1,18 +1,45 @@ // Copyright (C) 2013 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 12.5.6.1 -description: > - typeof Symbol() returns 'symbol'. - typeof Object(Symbol()) returns 'object'. +esid: sec-typeof-operator-runtime-semantics-evaluation +description: typeof Symbol() and Object(Symbol) +info: | + The typeof Operator + + Runtime Semantics: Evaluation + + ... + Return a String according to Table 35. + + #table-35 + + Symbol "symbol" + Object(Symbol()) "object" + features: [Symbol] ---*/ -assert.sameValue(typeof Symbol('A'), 'symbol', "`typeof Symbol('A')` is `'symbol'`"); -assert.sameValue(typeof Symbol(), 'symbol', "`typeof Symbol()` is `'symbol'`"); -var symA = Symbol(); -assert.sameValue(typeof symA, 'symbol', "`typeof symA` is `'symbol'`, after executing `var symA = Symbol();`"); +assert.sameValue( + typeof Symbol(), + "symbol", + "typeof Symbol() === 'symbol'" +); -var symB = Object(Symbol()); -assert.sameValue(typeof symB, 'object', "`typeof symB` is `'object'`, after executing `var symB = Object(Symbol());`"); +assert.sameValue( + typeof Symbol("A"), + "symbol", + "typeof Symbol('A') === 'symbol'" +); + +assert.sameValue( + typeof Object(Symbol()), + "object", + "typeof Object(Symbol()) === 'object'" +); + +assert.sameValue( + typeof Object(Symbol("A")), + "object", + "typeof Object(Symbol('A')) === 'object'" +); diff --git a/test/language/expressions/typeof/undefined.js b/test/language/expressions/typeof/undefined.js index 77eaf78321..ca8530fd30 100644 --- a/test/language/expressions/typeof/undefined.js +++ b/test/language/expressions/typeof/undefined.js @@ -2,20 +2,29 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -info: Result of applying "typeof" operator to undefined is "undefined" -es5id: 11.4.3_A3.1 -es6id: 12.5.6.1 -description: typeof undefined === "undefined" +esid: sec-typeof-operator-runtime-semantics-evaluation +description: typeof undefined and void 0 +info: | + The typeof Operator + + Runtime Semantics: Evaluation + + ... + Return a String according to Table 35. + + #table-35 + + Undefined "undefined" ---*/ assert.sameValue( typeof undefined, "undefined", - '#1: typeof undefined === "undefined". Actual: ' + (typeof undefined) + 'typeof undefined === "undefined"' ); assert.sameValue( typeof void 0, "undefined", - '#2: typeof void 0 === "undefined". Actual: ' + (typeof void 0) + 'typeof void 0 === "undefined"' ); diff --git a/test/language/expressions/typeof/unresolvable-reference.js b/test/language/expressions/typeof/unresolvable-reference.js index 333cc9ac84..bf0b03b0a9 100644 --- a/test/language/expressions/typeof/unresolvable-reference.js +++ b/test/language/expressions/typeof/unresolvable-reference.js @@ -2,12 +2,22 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -info: Operator "typeof" uses GetValue -es5id: 11.4.3_A2_T2 -es6id: 12.5.6.1 -description: If GetBase(x) is null, return "undefined" +esid: sec-typeof-operator-runtime-semantics-evaluation +description: If IsUnresolvableReference(val) is true, return "undefined". +info: | + The typeof Operator + + Runtime Semantics: Evaluation + + ... + If Type(val) is Reference, then + If IsUnresolvableReference(val) is true, return "undefined". + ... + ---*/ assert.sameValue( - typeof x, "undefined", '#1: typeof x === "undefined". Actual: ' + (typeof x) + typeof x, + "undefined", + "typeof x === 'undefined'" );