mirror of https://github.com/svaarala/duktape.git
Sami Vaarala
7 years ago
committed by
GitHub
15 changed files with 418 additions and 31 deletions
@ -0,0 +1,41 @@ |
|||
/*=== |
|||
function |
|||
propdesc isFinite: value=function:isFinite, writable=true, enumerable=false, configurable=true |
|||
propdesc length: value=1, writable=false, enumerable=false, configurable=true |
|||
propdesc name: value="isFinite", writable=false, enumerable=false, configurable=true |
|||
-Infinity false |
|||
-1e+100 true |
|||
-1234567890.2 true |
|||
-305419896 true |
|||
-0 true |
|||
0 true |
|||
305419896 true |
|||
1234567890.2 true |
|||
1e+100 true |
|||
Infinity false |
|||
NaN false |
|||
undefined false |
|||
null false |
|||
"" false |
|||
"123" false |
|||
true false |
|||
false false |
|||
[object Object] false |
|||
===*/ |
|||
|
|||
/*@include util-base.js@*/ |
|||
|
|||
print(typeof Number.isFinite); |
|||
print(Test.getPropDescString(Number, 'isFinite')); |
|||
print(Test.getPropDescString(Number.isFinite, 'length')); |
|||
print(Test.getPropDescString(Number.isFinite, 'name')); |
|||
|
|||
[ |
|||
-1 / 0, -1e100, -1234567890.2, -0x12345678, -0, |
|||
+0, 0x12345678, 1234567890.2, 1e100, 1 / 0, |
|||
0 / 0, |
|||
void 0, null, '', '123', true, false, |
|||
{ valueOf: function () { return 123.0; } } |
|||
].forEach(function (v) { |
|||
print(Test.valueToString(v), Test.valueToString(Number.isFinite(v))); |
|||
}); |
@ -0,0 +1,41 @@ |
|||
/*=== |
|||
function |
|||
propdesc isInteger: value=function:isInteger, writable=true, enumerable=false, configurable=true |
|||
propdesc length: value=1, writable=false, enumerable=false, configurable=true |
|||
propdesc name: value="isInteger", writable=false, enumerable=false, configurable=true |
|||
-Infinity false |
|||
-1e+100 true |
|||
-1234567890.2 false |
|||
-305419896 true |
|||
-0 true |
|||
0 true |
|||
305419896 true |
|||
1234567890.2 false |
|||
1e+100 true |
|||
Infinity false |
|||
NaN false |
|||
undefined false |
|||
null false |
|||
"" false |
|||
"123" false |
|||
true false |
|||
false false |
|||
[object Object] false |
|||
===*/ |
|||
|
|||
/*@include util-base.js@*/ |
|||
|
|||
print(typeof Number.isInteger); |
|||
print(Test.getPropDescString(Number, 'isInteger')); |
|||
print(Test.getPropDescString(Number.isInteger, 'length')); |
|||
print(Test.getPropDescString(Number.isInteger, 'name')); |
|||
|
|||
[ |
|||
-1 / 0, -1e100, -1234567890.2, -0x12345678, -0, |
|||
+0, 0x12345678, 1234567890.2, 1e100, 1 / 0, |
|||
0 / 0, |
|||
void 0, null, '', '123', true, false, |
|||
{ valueOf: function () { return 123.0; } } |
|||
].forEach(function (v) { |
|||
print(Test.valueToString(v), Test.valueToString(Number.isInteger(v))); |
|||
}); |
@ -0,0 +1,41 @@ |
|||
/*=== |
|||
function |
|||
propdesc isNaN: value=function:isNaN, writable=true, enumerable=false, configurable=true |
|||
propdesc length: value=1, writable=false, enumerable=false, configurable=true |
|||
propdesc name: value="isNaN", writable=false, enumerable=false, configurable=true |
|||
-Infinity false |
|||
-1e+100 false |
|||
-1234567890.2 false |
|||
-305419896 false |
|||
-0 false |
|||
0 false |
|||
305419896 false |
|||
1234567890.2 false |
|||
1e+100 false |
|||
Infinity false |
|||
NaN true |
|||
undefined false |
|||
null false |
|||
"" false |
|||
"123" false |
|||
true false |
|||
false false |
|||
[object Object] false |
|||
===*/ |
|||
|
|||
/*@include util-base.js@*/ |
|||
|
|||
print(typeof Number.isNaN); |
|||
print(Test.getPropDescString(Number, 'isNaN')); |
|||
print(Test.getPropDescString(Number.isNaN, 'length')); |
|||
print(Test.getPropDescString(Number.isNaN, 'name')); |
|||
|
|||
[ |
|||
-1 / 0, -1e100, -1234567890.2, -0x12345678, -0, |
|||
+0, 0x12345678, 1234567890.2, 1e100, 1 / 0, |
|||
0 / 0, |
|||
void 0, null, '', '123', true, false, |
|||
{ valueOf: function () { return 123.0; } } |
|||
].forEach(function (v) { |
|||
print(Test.valueToString(v), Test.valueToString(Number.isNaN(v))); |
|||
}); |
@ -0,0 +1,57 @@ |
|||
/*=== |
|||
function |
|||
propdesc isSafeInteger: value=function:isSafeInteger, writable=true, enumerable=false, configurable=true |
|||
propdesc length: value=1, writable=false, enumerable=false, configurable=true |
|||
propdesc name: value="isSafeInteger", writable=false, enumerable=false, configurable=true |
|||
-Infinity false |
|||
-1e+100 false |
|||
-1234567890.2 false |
|||
-305419896 true |
|||
-0 true |
|||
0 true |
|||
305419896 true |
|||
1234567890.2 false |
|||
1e+100 false |
|||
Infinity false |
|||
NaN false |
|||
-9007199254740992 false |
|||
-9007199254740991 true |
|||
-9007199254740990 true |
|||
9007199254740992 false |
|||
9007199254740991 true |
|||
9007199254740990 true |
|||
undefined false |
|||
null false |
|||
"" false |
|||
"123" false |
|||
true false |
|||
false false |
|||
[object Object] false |
|||
===*/ |
|||
|
|||
/*@include util-base.js@*/ |
|||
|
|||
print(typeof Number.isSafeInteger); |
|||
print(Test.getPropDescString(Number, 'isSafeInteger')); |
|||
print(Test.getPropDescString(Number.isSafeInteger, 'length')); |
|||
print(Test.getPropDescString(Number.isSafeInteger, 'name')); |
|||
|
|||
[ |
|||
-1 / 0, -1e100, -1234567890.2, -0x12345678, -0, |
|||
+0, 0x12345678, 1234567890.2, 1e100, 1 / 0, |
|||
0 / 0, |
|||
|
|||
// Specific corner case values: note that fractions are not actually
|
|||
// significant so it suffices to test for integers.
|
|||
-9007199254740992.0, |
|||
-9007199254740991.0, |
|||
-9007199254740990.0, |
|||
9007199254740992.0, |
|||
9007199254740991.0, |
|||
9007199254740990.0, |
|||
|
|||
void 0, null, '', '123', true, false, |
|||
{ valueOf: function () { return 123.0; } } |
|||
].forEach(function (v) { |
|||
print(Test.valueToString(v), Test.valueToString(Number.isSafeInteger(v))); |
|||
}); |
@ -0,0 +1,94 @@ |
|||
/* |
|||
* Basic test utilities in a global 'Test' binding. |
|||
*/ |
|||
|
|||
(function initTest() { |
|||
var GLOBAL = new Function('return this')(); |
|||
var Test = GLOBAL.Test; |
|||
if (typeof Test !== 'object') { |
|||
Test = {}; |
|||
Object.defineProperty(GLOBAL, 'Test', { |
|||
value: Test, writable: false, enumerable: false, configurable: false |
|||
}); |
|||
} |
|||
|
|||
// Summarize any value to a printable string, avoiding side effects where
|
|||
// possible, preserving details like zero sign.
|
|||
function valueToString(x) { |
|||
if (x === void 0) { |
|||
return 'undefined'; |
|||
} else if (x === null) { |
|||
return 'null'; |
|||
} else if (typeof x === 'boolean') { |
|||
return String(x); |
|||
} else if (typeof x === 'number') { |
|||
if (x !== 0) { |
|||
return String(x); |
|||
} else { |
|||
return (1 / x > 0) ? '0' : '-0'; |
|||
} |
|||
} else if (typeof x === 'string') { |
|||
return JSON.stringify(x); |
|||
} else if (typeof x === 'symbol') { |
|||
return String(x); |
|||
} else if (typeof x === 'object') { |
|||
return Object.prototype.toString.call(x); |
|||
} else if (typeof x === 'function') { |
|||
var pd = Object.getOwnPropertyDescriptor(x, 'name'); |
|||
if (pd && typeof pd.value === 'string') { |
|||
return 'function:' + pd.value; |
|||
} else { |
|||
return 'function'; |
|||
} |
|||
} else if (typeof x === 'pointer') { |
|||
if (String(x) === 'null') { |
|||
return 'pointer:null'; |
|||
} else { |
|||
return 'pointer:non-null'; // specific pointer is very rarely interesting for tests
|
|||
} |
|||
} else if (typeof x === 'buffer') { |
|||
// No longer used in Duktape 2.x.
|
|||
return 'buffer:' + x.length; |
|||
} else { |
|||
return 'unknown:' + String(x); |
|||
} |
|||
} |
|||
|
|||
// Get property descriptor string for arbitrary object and key.
|
|||
function getPropDescString(obj, key) { |
|||
if (obj === void 0) { |
|||
return 'propdesc ' + key + ': undefined object'; |
|||
} else if (obj === null) { |
|||
return 'propdesc ' + key + ': null object'; |
|||
} else { |
|||
try { |
|||
var pd = Object.getOwnPropertyDescriptor(obj, key); |
|||
var parts = []; |
|||
if (typeof pd.value !== 'undefined') { |
|||
parts.push('value=' + valueToString(pd.value)); |
|||
} |
|||
if (typeof pd.writable !== 'undefined') { |
|||
parts.push('writable=' + valueToString(pd.writable)); |
|||
} |
|||
if (typeof pd.enumerable !== 'undefined') { |
|||
parts.push('enumerable=' + valueToString(pd.enumerable)); |
|||
} |
|||
if (typeof pd.configurable !== 'undefined') { |
|||
parts.push('configurable=' + valueToString(pd.configurable)); |
|||
} |
|||
if (typeof pd.get !== 'undefined') { |
|||
parts.push('get=' + valueToString(pd.get)); |
|||
} |
|||
if (typeof pd.set !== 'undefined') { |
|||
parts.push('set=' + valueToString(pd.set)); |
|||
} |
|||
return 'propdesc ' + key + ': ' + parts.join(', '); |
|||
} catch (e) { |
|||
return 'propdesc ' + key + ': ' + String(e); |
|||
} |
|||
} |
|||
} |
|||
|
|||
Test.valueToString = valueToString; |
|||
Test.getPropDescString = getPropDescString; |
|||
}()); |
Loading…
Reference in new issue