Kaynağa Gözat

Implement Error cause and other Error specs (#992)

* add error related test262 specs
* add method ambiguity tests
* fix error spec test fails
* add Error cause
Gökhan Kurt 3 yıl önce
ebeveyn
işleme
a0289f9204
57 değiştirilmiş dosya ile 892 ekleme ve 553 silme
  1. 3 7
      Jint.Tests.Test262/Test262Test.cs
  2. 327 0
      Jint.Tests.Test262/harness/deepEqual.js
  3. 17 0
      Jint.Tests.Test262/harness/hidden-constructors.js
  4. 0 51
      Jint.Tests.Test262/test/built-ins/Error/S15.11.1.1_A1_T1.js
  5. 0 19
      Jint.Tests.Test262/test/built-ins/Error/S15.11.1.1_A2_T1.js
  6. 0 20
      Jint.Tests.Test262/test/built-ins/Error/S15.11.1.1_A3_T1.js
  7. 0 20
      Jint.Tests.Test262/test/built-ins/Error/S15.11.1_A1_T1.js
  8. 0 51
      Jint.Tests.Test262/test/built-ins/Error/S15.11.2.1_A1_T1.js
  9. 0 19
      Jint.Tests.Test262/test/built-ins/Error/S15.11.2.1_A2_T1.js
  10. 0 20
      Jint.Tests.Test262/test/built-ins/Error/S15.11.2.1_A3_T1.js
  11. 0 29
      Jint.Tests.Test262/test/built-ins/Error/S15.11.3_A1_T1.js
  12. 0 25
      Jint.Tests.Test262/test/built-ins/Error/S15.11.3_A2_T1.js
  13. 52 0
      Jint.Tests.Test262/test/built-ins/Error/cause_abrupt.js
  14. 37 0
      Jint.Tests.Test262/test/built-ins/Error/cause_property.js
  15. 37 0
      Jint.Tests.Test262/test/built-ins/Error/constructor.js
  16. 23 0
      Jint.Tests.Test262/test/built-ins/Error/instance-prototype.js
  17. 20 0
      Jint.Tests.Test262/test/built-ins/Error/internal-prototype.js
  18. 24 0
      Jint.Tests.Test262/test/built-ins/Error/is-a-constructor.js
  19. 12 0
      Jint.Tests.Test262/test/built-ins/Error/length.js
  20. 11 0
      Jint.Tests.Test262/test/built-ins/Error/name.js
  21. 16 0
      Jint.Tests.Test262/test/built-ins/Error/prop-desc.js
  22. 0 1
      Jint.Tests.Test262/test/built-ins/Error/proto-from-ctor-realm.js
  23. 7 5
      Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.3.1_A1_T1.js
  24. 11 19
      Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.3.1_A2_T1.js
  25. 4 25
      Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.3.1_A3_T1.js
  26. 1 8
      Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.3.1_A4_T1.js
  27. 4 8
      Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.4_A1.js
  28. 1 7
      Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.4_A2.js
  29. 3 9
      Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.4_A3.js
  30. 4 10
      Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.4_A4.js
  31. 0 18
      Jint.Tests.Test262/test/built-ins/Error/prototype/constructor/S15.11.4.1_A1_T1.js
  32. 5 35
      Jint.Tests.Test262/test/built-ins/Error/prototype/constructor/S15.11.4.1_A1_T2.js
  33. 14 0
      Jint.Tests.Test262/test/built-ins/Error/prototype/constructor/prop-desc.js
  34. 0 11
      Jint.Tests.Test262/test/built-ins/Error/prototype/message/15.11.4.3-1.js
  35. 0 16
      Jint.Tests.Test262/test/built-ins/Error/prototype/message/S15.11.4.3_A1.js
  36. 0 16
      Jint.Tests.Test262/test/built-ins/Error/prototype/message/S15.11.4.3_A2.js
  37. 14 0
      Jint.Tests.Test262/test/built-ins/Error/prototype/message/prop-desc.js
  38. 0 11
      Jint.Tests.Test262/test/built-ins/Error/prototype/name/15.11.4.2-1.js
  39. 0 16
      Jint.Tests.Test262/test/built-ins/Error/prototype/name/S15.11.4.2_A1.js
  40. 0 16
      Jint.Tests.Test262/test/built-ins/Error/prototype/name/S15.11.4.2_A2.js
  41. 14 0
      Jint.Tests.Test262/test/built-ins/Error/prototype/name/prop-desc.js
  42. 34 0
      Jint.Tests.Test262/test/built-ins/Error/prototype/no-error-data.js
  43. 2 2
      Jint.Tests.Test262/test/built-ins/Error/prototype/toString/15.11.4.4-8-2.js
  44. 0 16
      Jint.Tests.Test262/test/built-ins/Error/prototype/toString/S15.11.4.4_A1.js
  45. 2 15
      Jint.Tests.Test262/test/built-ins/Error/prototype/toString/S15.11.4.4_A2.js
  46. 32 0
      Jint.Tests.Test262/test/built-ins/Error/prototype/toString/called-as-function.js
  47. 18 0
      Jint.Tests.Test262/test/built-ins/Error/prototype/toString/invalid-receiver.js
  48. 33 0
      Jint.Tests.Test262/test/built-ins/Error/prototype/toString/not-a-constructor.js
  49. 13 0
      Jint.Tests.Test262/test/built-ins/Error/prototype/toString/prop-desc.js
  50. 20 0
      Jint.Tests.Test262/test/built-ins/Error/prototype/toString/undefined-props.js
  51. 13 0
      Jint.Tests.Test262/test/built-ins/Error/the-initial-value-of-errorprototypemessage-is-the-empty-string.js
  52. 13 0
      Jint.Tests.Test262/test/built-ins/Error/tostring-1.js
  53. 21 0
      Jint.Tests.Test262/test/built-ins/Error/tostring-2.js
  54. 12 0
      Jint.Tests/Runtime/MethodAmbiguityTests.cs
  55. 10 2
      Jint/Native/Error/ErrorConstructor.cs
  56. 0 15
      Jint/Native/Error/ErrorInstance.cs
  57. 8 11
      Jint/Native/Error/ErrorPrototype.cs

+ 3 - 7
Jint.Tests.Test262/Test262Test.cs

@@ -59,6 +59,7 @@ namespace Jint.Tests.Test262
                 "propertyHelper.js",
                 "compareArray.js",
                 "decimalToHexString.js",
+                "deepEqual.js",
                 "proxyTrapsHelper.js",
                 "dateConstants.js",
                 "assertRelativeDateMs.js",
@@ -70,7 +71,8 @@ namespace Jint.Tests.Test262
                 "fnGlobalObject.js",
                 "testTypedArray.js",
                 "detachArrayBuffer.js",
-                "byteConversionValues.js"
+                "byteConversionValues.js",
+                "hidden-constructors.js",
             };
 
             Sources = new Dictionary<string, Script>(files.Length);
@@ -145,12 +147,6 @@ namespace Jint.Tests.Test262
                 var files = includes.Groups[1].Captures[0].Value.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
                 foreach (var file in files)
                 {
-                    if (file == "hidden-constructors.js")
-                    {
-                        // suite refers to non-existent file
-                        continue;
-                    }
-
                     engine.Execute(Sources[file.Trim()]);
                 }
             }

+ 327 - 0
Jint.Tests.Test262/harness/deepEqual.js

@@ -0,0 +1,327 @@
+// Copyright 2019 Ron Buckton. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+description: >
+  Compare two values structurally
+defines: [assert.deepEqual]
+---*/
+
+assert.deepEqual = function(actual, expected, message) {
+  var format = assert.deepEqual.format;
+  assert(
+    assert.deepEqual._compare(actual, expected),
+    `Expected ${format(actual)} to be structurally equal to ${format(expected)}. ${(message || '')}`
+  );
+};
+
+assert.deepEqual.format = function(value, seen) {
+  switch (typeof value) {
+    case 'string':
+      return typeof JSON !== "undefined" ? JSON.stringify(value) : `"${value}"`;
+    case 'number':
+    case 'boolean':
+    case 'symbol':
+    case 'bigint':
+      return value.toString();
+    case 'undefined':
+      return 'undefined';
+    case 'function':
+      return `[Function${value.name ? `: ${value.name}` : ''}]`;
+    case 'object':
+      if (value === null) return 'null';
+      if (value instanceof Date) return `Date "${value.toISOString()}"`;
+      if (value instanceof RegExp) return value.toString();
+      if (!seen) {
+        seen = {
+          counter: 0,
+          map: new Map()
+        };
+      }
+
+      let usage = seen.map.get(value);
+      if (usage) {
+        usage.used = true;
+        return `[Ref: #${usage.id}]`;
+      }
+
+      usage = { id: ++seen.counter, used: false };
+      seen.map.set(value, usage);
+
+      if (typeof Set !== "undefined" && value instanceof Set) {
+        return `Set {${Array.from(value).map(value => assert.deepEqual.format(value, seen)).join(', ')}}${usage.used ? ` as #${usage.id}` : ''}`;
+      }
+      if (typeof Map !== "undefined" && value instanceof Map) {
+        return `Map {${Array.from(value).map(pair => `${assert.deepEqual.format(pair[0], seen)} => ${assert.deepEqual.format(pair[1], seen)}}`).join(', ')}}${usage.used ? ` as #${usage.id}` : ''}`;
+      }
+      if (Array.isArray ? Array.isArray(value) : value instanceof Array) {
+        return `[${value.map(value => assert.deepEqual.format(value, seen)).join(', ')}]${usage.used ? ` as #${usage.id}` : ''}`;
+      }
+      let tag = Symbol.toStringTag in value ? value[Symbol.toStringTag] : 'Object';
+      if (tag === 'Object' && Object.getPrototypeOf(value) === null) {
+        tag = '[Object: null prototype]';
+      }
+      return `${tag ? `${tag} ` : ''}{ ${Object.keys(value).map(key => `${key.toString()}: ${assert.deepEqual.format(value[key], seen)}`).join(', ')} }${usage.used ? ` as #${usage.id}` : ''}`;
+    default:
+      return typeof value;
+  }
+};
+
+assert.deepEqual._compare = (function () {
+  var EQUAL = 1;
+  var NOT_EQUAL = -1;
+  var UNKNOWN = 0;
+
+  function deepEqual(a, b) {
+    return compareEquality(a, b) === EQUAL;
+  }
+
+  function compareEquality(a, b, cache) {
+    return compareIf(a, b, isOptional, compareOptionality)
+      || compareIf(a, b, isPrimitiveEquatable, comparePrimitiveEquality)
+      || compareIf(a, b, isObjectEquatable, compareObjectEquality, cache)
+      || NOT_EQUAL;
+  }
+
+  function compareIf(a, b, test, compare, cache) {
+    return !test(a)
+      ? !test(b) ? UNKNOWN : NOT_EQUAL
+      : !test(b) ? NOT_EQUAL : cacheComparison(a, b, compare, cache);
+  }
+
+  function tryCompareStrictEquality(a, b) {
+    return a === b ? EQUAL : UNKNOWN;
+  }
+
+  function tryCompareTypeOfEquality(a, b) {
+    return typeof a !== typeof b ? NOT_EQUAL : UNKNOWN;
+  }
+
+  function tryCompareToStringTagEquality(a, b) {
+    var aTag = Symbol.toStringTag in a ? a[Symbol.toStringTag] : undefined;
+    var bTag = Symbol.toStringTag in b ? b[Symbol.toStringTag] : undefined;
+    return aTag !== bTag ? NOT_EQUAL : UNKNOWN;
+  }
+
+  function isOptional(value) {
+    return value === undefined
+      || value === null;
+  }
+
+  function compareOptionality(a, b) {
+    return tryCompareStrictEquality(a, b)
+      || NOT_EQUAL;
+  }
+
+  function isPrimitiveEquatable(value) {
+    switch (typeof value) {
+      case 'string':
+      case 'number':
+      case 'bigint':
+      case 'boolean':
+      case 'symbol':
+        return true;
+      default:
+        return isBoxed(value);
+    }
+  }
+
+  function comparePrimitiveEquality(a, b) {
+    if (isBoxed(a)) a = a.valueOf();
+    if (isBoxed(b)) b = b.valueOf();
+    return tryCompareStrictEquality(a, b)
+      || tryCompareTypeOfEquality(a, b)
+      || compareIf(a, b, isNaNEquatable, compareNaNEquality)
+      || NOT_EQUAL;
+  }
+
+  function isNaNEquatable(value) {
+    return typeof value === 'number';
+  }
+
+  function compareNaNEquality(a, b) {
+    return isNaN(a) && isNaN(b) ? EQUAL : NOT_EQUAL;
+  }
+
+  function isObjectEquatable(value) {
+    return typeof value === 'object';
+  }
+
+  function compareObjectEquality(a, b, cache) {
+    if (!cache) cache = new Map();
+    return getCache(cache, a, b)
+      || setCache(cache, a, b, EQUAL) // consider equal for now
+      || cacheComparison(a, b, tryCompareStrictEquality, cache)
+      || cacheComparison(a, b, tryCompareToStringTagEquality, cache)
+      || compareIf(a, b, isValueOfEquatable, compareValueOfEquality)
+      || compareIf(a, b, isToStringEquatable, compareToStringEquality)
+      || compareIf(a, b, isArrayLikeEquatable, compareArrayLikeEquality, cache)
+      || compareIf(a, b, isStructurallyEquatable, compareStructuralEquality, cache)
+      || compareIf(a, b, isIterableEquatable, compareIterableEquality, cache)
+      || cacheComparison(a, b, fail, cache);
+  }
+
+  function isBoxed(value) {
+    return value instanceof String
+      || value instanceof Number
+      || value instanceof Boolean
+      || typeof Symbol === 'function' && value instanceof Symbol
+      || typeof BigInt === 'function' && value instanceof BigInt;
+  }
+
+  function isValueOfEquatable(value) {
+    return value instanceof Date;
+  }
+
+  function compareValueOfEquality(a, b) {
+    return compareIf(a.valueOf(), b.valueOf(), isPrimitiveEquatable, comparePrimitiveEquality)
+      || NOT_EQUAL;
+  }
+
+  function isToStringEquatable(value) {
+    return value instanceof RegExp;
+  }
+
+  function compareToStringEquality(a, b) {
+    return compareIf(a.toString(), b.toString(), isPrimitiveEquatable, comparePrimitiveEquality)
+      || NOT_EQUAL;
+  }
+
+  function isArrayLikeEquatable(value) {
+    return (Array.isArray ? Array.isArray(value) : value instanceof Array)
+      || (typeof Uint8Array === 'function' && value instanceof Uint8Array)
+      || (typeof Uint8ClampedArray === 'function' && value instanceof Uint8ClampedArray)
+      || (typeof Uint16Array === 'function' && value instanceof Uint16Array)
+      || (typeof Uint32Array === 'function' && value instanceof Uint32Array)
+      || (typeof Int8Array === 'function' && value instanceof Int8Array)
+      || (typeof Int16Array === 'function' && value instanceof Int16Array)
+      || (typeof Int32Array === 'function' && value instanceof Int32Array)
+      || (typeof Float32Array === 'function' && value instanceof Float32Array)
+      || (typeof Float64Array === 'function' && value instanceof Float64Array)
+      || (typeof BigUint64Array === 'function' && value instanceof BigUint64Array)
+      || (typeof BigInt64Array === 'function' && value instanceof BigInt64Array);
+  }
+
+  function compareArrayLikeEquality(a, b, cache) {
+    if (a.length !== b.length) return NOT_EQUAL;
+    for (var i = 0; i < a.length; i++) {
+      if (compareEquality(a[i], b[i], cache) === NOT_EQUAL) {
+        return NOT_EQUAL;
+      }
+    }
+    return EQUAL;
+  }
+
+  function isStructurallyEquatable(value) {
+    return !(typeof Promise === 'function' && value instanceof Promise // only comparable by reference
+      || typeof WeakMap === 'function' && value instanceof WeakMap // only comparable by reference
+      || typeof WeakSet === 'function' && value instanceof WeakSet // only comparable by reference
+      || typeof Map === 'function' && value instanceof Map // comparable via @@iterator
+      || typeof Set === 'function' && value instanceof Set); // comparable via @@iterator
+  }
+
+  function compareStructuralEquality(a, b, cache) {
+    var aKeys = [];
+    for (var key in a) aKeys.push(key);
+
+    var bKeys = [];
+    for (var key in b) bKeys.push(key);
+
+    if (aKeys.length !== bKeys.length) {
+      return NOT_EQUAL;
+    }
+
+    aKeys.sort();
+    bKeys.sort();
+
+    for (var i = 0; i < aKeys.length; i++) {
+      var aKey = aKeys[i];
+      var bKey = bKeys[i];
+      if (compareEquality(aKey, bKey, cache) === NOT_EQUAL) {
+        return NOT_EQUAL;
+      }
+      if (compareEquality(a[aKey], b[bKey], cache) === NOT_EQUAL) {
+        return NOT_EQUAL;
+      }
+    }
+
+    return compareIf(a, b, isIterableEquatable, compareIterableEquality, cache)
+      || EQUAL;
+  }
+
+  function isIterableEquatable(value) {
+    return typeof Symbol === 'function'
+      && typeof value[Symbol.iterator] === 'function';
+  }
+
+  function compareIteratorEquality(a, b, cache) {
+    if (typeof Map === 'function' && a instanceof Map && b instanceof Map ||
+      typeof Set === 'function' && a instanceof Set && b instanceof Set) {
+      if (a.size !== b.size) return NOT_EQUAL; // exit early if we detect a difference in size
+    }
+
+    var ar, br;
+    while (true) {
+      ar = a.next();
+      br = b.next();
+      if (ar.done) {
+        if (br.done) return EQUAL;
+        if (b.return) b.return();
+        return NOT_EQUAL;
+      }
+      if (br.done) {
+        if (a.return) a.return();
+        return NOT_EQUAL;
+      }
+      if (compareEquality(ar.value, br.value, cache) === NOT_EQUAL) {
+        if (a.return) a.return();
+        if (b.return) b.return();
+        return NOT_EQUAL;
+      }
+    }
+  }
+
+  function compareIterableEquality(a, b, cache) {
+    return compareIteratorEquality(a[Symbol.iterator](), b[Symbol.iterator](), cache);
+  }
+
+  function cacheComparison(a, b, compare, cache) {
+    var result = compare(a, b, cache);
+    if (cache && (result === EQUAL || result === NOT_EQUAL)) {
+      setCache(cache, a, b, /** @type {EQUAL | NOT_EQUAL} */(result));
+    }
+    return result;
+  }
+
+  function fail() {
+    return NOT_EQUAL;
+  }
+
+  function setCache(cache, left, right, result) {
+    var otherCache;
+
+    otherCache = cache.get(left);
+    if (!otherCache) cache.set(left, otherCache = new Map());
+    otherCache.set(right, result);
+
+    otherCache = cache.get(right);
+    if (!otherCache) cache.set(right, otherCache = new Map());
+    otherCache.set(left, result);
+  }
+
+  function getCache(cache, left, right) {
+    var otherCache;
+    var result;
+
+    otherCache = cache.get(left);
+    result = otherCache && otherCache.get(right);
+    if (result) return result;
+
+    otherCache = cache.get(right);
+    result = otherCache && otherCache.get(left);
+    if (result) return result;
+
+    return UNKNOWN;
+  }
+
+  return deepEqual;
+})();

+ 17 - 0
Jint.Tests.Test262/harness/hidden-constructors.js

@@ -0,0 +1,17 @@
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: |
+  Provides uniform access to built-in constructors that are not exposed to the global object.
+defines:
+  - AsyncArrowFunction
+  - AsyncFunction
+  - AsyncGeneratorFunction
+  - GeneratorFunction
+---*/
+
+var AsyncArrowFunction = Object.getPrototypeOf(async () => {}).constructor;
+var AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
+var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
+var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;

+ 0 - 51
Jint.Tests.Test262/test/built-ins/Error/S15.11.1.1_A1_T1.js

@@ -1,51 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: |
-    If the argument "message" is not undefined, the message property of the newly constructed object is
-    set to ToString(message)
-es5id: 15.11.1.1_A1_T1
-description: Checking message property of different error objects
----*/
-
-function otherScope(msg)
-{
-  return Error(msg);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-var err1 = Error('msg1');
-if (err1.message !== "msg1") {
-  $ERROR('#1: var err1=Error(\'msg1\'); err1.message==="msg1". Actual: ' + err1.message);
-}
-//
-//////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#2
-var err2 = otherScope('msg2');
-if (err2.message !== "msg2") {
-  $ERROR('#2: function otherScope(msg){return Error(msg);} var err2=otherScope(\'msg2\'); err2.message==="msg2". Actual: ' + err2.message);
-}
-//
-//////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#3
-var err3 = otherScope();
-if (err3.hasOwnProperty('message')) {
-  $ERROR('#3: function otherScope(msg){return Error(msg);} var err3=otherScope(); err3.hasOwnProperty("message"). Actual: ' + err3.message);
-}
-//
-//////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#4
-var err4 = eval("Error('msg4')");
-if (err4.message !== "msg4") {
-  $ERROR('#4: var err4=eval("Error(\'msg4\')"); err4.message==="msg4". Actual: ' + err4.message);
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 0 - 19
Jint.Tests.Test262/test/built-ins/Error/S15.11.1.1_A2_T1.js

@@ -1,19 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: |
-    The [[Prototype]] property of the newly constructed object is set to the original Error prototype
-    object, the one that is the initial value of Error.prototype (15.11.3.1)
-es5id: 15.11.1.1_A2_T1
-description: Checking prototype of the newly constructed Error object
----*/
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-var err1 = Error('msg1');
-if (!Error.prototype.isPrototypeOf(err1)) {
-  $ERROR('#1: var err1=Error(\'msg1\'); Error.prototype.isPrototypeOf(err1) return true. Actual: ' + Error.prototype.isPrototypeOf(err1));
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 0 - 20
Jint.Tests.Test262/test/built-ins/Error/S15.11.1.1_A3_T1.js

@@ -1,20 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: The [[Class]] property of the newly constructed object is set to "Error"
-es5id: 15.11.1.1_A3_T1
-description: >
-    Checking Class of the newly constructed Error object using
-    toSting() function
----*/
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-Error.prototype.toString = Object.prototype.toString;
-var err1 = Error();
-if (err1.toString() !== '[object ' + 'Error' + ']') {
-  $ERROR('#1: Error.prototype.toString=Object.prototype.toString; var err1=Error(); err1.toString()===\'[object Error]\'. Actual: ' + err1.toString());
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 0 - 20
Jint.Tests.Test262/test/built-ins/Error/S15.11.1_A1_T1.js

@@ -1,20 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: |
-    The function call Error(...) is equivalent to the object creation expression new
-    Error(...) with the same arguments
-es5id: 15.11.1_A1_T1
-description: Checking constructor of the newly constructed Error object
----*/
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-Error.prototype.toString = Object.prototype.toString;
-var err1 = Error();
-if (err1.constructor !== Error) {
-  $ERROR('#1: Error.prototype.toString=Object.prototype.toString; var err1=Error(); err1.constructor===Error. Actual: ' + err1.constructor);
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 0 - 51
Jint.Tests.Test262/test/built-ins/Error/S15.11.2.1_A1_T1.js

@@ -1,51 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: |
-    If the argument "message" is not undefined, the message property of the newly constructed object is
-    set to ToString(message)
-es5id: 15.11.2.1_A1_T1
-description: Checking message property of different error objects
----*/
-
-function otherScope(msg)
-{
-  return new Error(msg);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-var err1 = new Error('msg1');
-if (err1.message !== "msg1") {
-  $ERROR('#1: var err1=new Error(\'msg1\'); err1.message==="msg1". Actual: ' + err1.message);
-}
-//
-//////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#2
-var err2 = otherScope('msg2');
-if (err2.message !== "msg2") {
-  $ERROR('#2: function otherScope(msg){return new Error(msg);} var err2=otherScope(\'msg2\'); err2.message==="msg2". Actual: ' + err2.message);
-}
-//
-//////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#3
-var err3 = otherScope();
-if (err3.hasOwnProperty('message')) {
-  $ERROR('#3: function otherScope(msg){return new Error(msg);} var err3=otherScope(); err3.hasOwnProperty("message"). Actual: ' + err3.message);
-}
-//
-//////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#4
-var err4 = eval("new Error('msg4')");
-if (err4.message !== "msg4") {
-  $ERROR('#4: var err4=eval("new Error(\'msg4\')"); err4.message==="msg4". Actual: ' + err4.message);
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 0 - 19
Jint.Tests.Test262/test/built-ins/Error/S15.11.2.1_A2_T1.js

@@ -1,19 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: |
-    The [[Prototype]] property of the newly constructed object is set to the original Error prototype
-    object, the one that is the initial value of Error.prototype (15.11.3.1)
-es5id: 15.11.2.1_A2_T1
-description: Checking prototype of the newly constructed Error object
----*/
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-var err1 = new Error('msg1');
-if (!Error.prototype.isPrototypeOf(err1)) {
-  $ERROR('#1: Error.prototype.isPrototypeOf(err1) return true. Actual: ' + Error.prototype.isPrototypeOf(err1));
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 0 - 20
Jint.Tests.Test262/test/built-ins/Error/S15.11.2.1_A3_T1.js

@@ -1,20 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: The [[Class]] property of the newly constructed object is set to "Error"
-es5id: 15.11.2.1_A3_T1
-description: >
-    Checking Class of the newly constructed Error object using
-    toSting() function
----*/
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-Error.prototype.toString = Object.prototype.toString;
-var err1 = new Error();
-if (err1.toString() !== '[object ' + 'Error' + ']') {
-  $ERROR('#1: err1.toString()===\'[object Error]\'. Actual: ' + err1.toString());
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 0 - 29
Jint.Tests.Test262/test/built-ins/Error/S15.11.3_A1_T1.js

@@ -1,29 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: |
-    The value of the internal [[Prototype]] property of the Error constructor
-    is the Function prototype object(15.3.4)
-es5id: 15.11.3_A1_T1
-description: >
-    Checking prototype of constructor of the newly constructed Error
-    object
----*/
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-var err1 = Error("err");
-if (!Function.prototype.isPrototypeOf(err1.constructor)) {
-  $ERROR('#1: var err1=Error("err"); Function.prototype.isPrototypeOf(err1.constructor) return true. Actual:' + Function.prototype.isPrototypeOf(err1.constructor));
-}
-//
-//////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#2
-if (!Function.prototype.isPrototypeOf(Error.constructor)) {
-  $ERROR('#2: Function.prototype.isPrototypeOf(Error.constructor) return true. Actual:' + Function.prototype.isPrototypeOf(Error.constructor));
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 0 - 25
Jint.Tests.Test262/test/built-ins/Error/S15.11.3_A2_T1.js

@@ -1,25 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: The length property value is 1
-es5id: 15.11.3_A2_T1
-description: Checking length property
----*/
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-var err1 = Error("err");
-if (err1.constructor.length !== 1) {
-  $ERROR('#1: var err1=Error("err"); err1.constructor.length===1. Actual: ' + err1.constructor.length);
-}
-//
-//////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#2
-if (Error.constructor.length !== 1) {
-  $ERROR('#2: Error.constructor.length===1. Actual: ' + Error.constructor.length);
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 52 - 0
Jint.Tests.Test262/test/built-ins/Error/cause_abrupt.js

@@ -0,0 +1,52 @@
+// Copyright (C) 2021 Chengzhong Wu. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: InstallErrorCause on abrupt completions
+info: |
+  Error ( message [ , options ] )
+
+  ...
+  4. Perform ? InstallErrorCause(O, options).
+  ...
+
+  20.5.8.1 InstallErrorCause ( O, options )
+
+  1. If Type(options) is Object and ? HasProperty(options, "cause") is true, then
+    a. Let cause be ? Get(options, "cause").
+    b. Perform ! CreateNonEnumerableDataPropertyOrThrow(O, "cause", cause).
+  ...
+
+esid: sec-error-message
+features: [error-cause]
+---*/
+
+var message = "my-message";
+var options;
+
+//////////////////////////////////////////////////////////////////////////////
+// CHECK#0
+options = new Proxy({}, {
+  has(target, prop) {
+    if (prop === "cause") {
+      throw new Test262Error("HasProperty");
+    }
+    return prop in target;
+  },
+});
+assert.throws(Test262Error, function () {
+  new Error(message, options);
+}, "HasProperty");
+//////////////////////////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////////////
+// CHECK#1
+options = {
+  get cause() {
+    throw new Test262Error("Get Cause");
+  },
+};
+assert.throws(Test262Error, function () {
+  new Error(message, options);
+}, "Get Cause");
+//////////////////////////////////////////////////////////////////////////////

+ 37 - 0
Jint.Tests.Test262/test/built-ins/Error/cause_property.js

@@ -0,0 +1,37 @@
+// Copyright (C) 2021 Chengzhong Wu. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: Error constructor creates own cause property
+info: |
+  Error ( message [ , options ] )
+
+  ...
+  4. Perform ? InstallErrorCause(O, options).
+  ...
+
+  20.5.8.1 InstallErrorCause ( O, options )
+
+  1. If Type(options) is Object and ? HasProperty(options, "cause") is true, then
+    a. Let cause be ? Get(options, "cause").
+    b. Perform ! CreateNonEnumerableDataPropertyOrThrow(O, "cause", cause).
+  ...
+
+esid: sec-error-message
+features: [error-cause]
+includes: [propertyHelper.js]
+---*/
+
+var message = "my-message";
+var cause = { message: "my-cause" };
+var error = new Error(message, { cause });
+
+verifyProperty(error, "cause", {
+  configurable: true,
+  enumerable: false,
+  writeable: true,
+  value: cause,
+});
+
+verifyProperty(new Error(message), "cause", undefined);
+verifyProperty(new Error(message, { cause: undefined }), "cause", { value: undefined });

+ 37 - 0
Jint.Tests.Test262/test/built-ins/Error/constructor.js

@@ -0,0 +1,37 @@
+// Copyright (C) 2021 Chengzhong Wu. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: Error constructor creates own properties in sequence
+info: |
+  Error ( message [ , options ] )
+
+  ...
+  4. Perform ? InstallErrorCause(O, options).
+  ...
+
+esid: sec-error-message
+features: [error-cause]
+includes: [deepEqual.js]
+---*/
+
+var message = "my-message";
+var cause = { message: "my-cause" };
+
+var sequence = [];
+new Error(
+  {
+    toString() {
+      sequence.push("toString");
+      return message;
+    },
+  },
+  {
+    get cause() {
+      sequence.push("cause");
+      return cause;
+    },
+  },
+);
+
+assert.deepEqual(sequence, [ "toString", "cause" ], "accessing own properties on sequence");

+ 23 - 0
Jint.Tests.Test262/test/built-ins/Error/instance-prototype.js

@@ -0,0 +1,23 @@
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-error.prototype
+description: >
+  The initial value of Error.prototype is the Error prototype object.
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+  Error.prototype.isPrototypeOf(new Error()), true,
+  'Error.prototype.isPrototypeOf(new Error()) returns true'
+);
+
+assert.sameValue(
+  Error.prototype.isPrototypeOf(Error()), true,
+  'Error.prototype.isPrototypeOf(Error()) returns true'
+);
+
+verifyNotEnumerable(Error, 'prototype');
+verifyNotWritable(Error, 'prototype');
+verifyNotConfigurable(Error, 'prototype');

+ 20 - 0
Jint.Tests.Test262/test/built-ins/Error/internal-prototype.js

@@ -0,0 +1,20 @@
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-properties-of-the-error-constructor
+description: >
+  The Error constructor has a [[Prototype]] internal slot whose value is %Function.prototype%.
+---*/
+
+assert.sameValue(
+  Function.prototype.isPrototypeOf(Error().constructor),
+  true,
+  'Function.prototype.isPrototypeOf(err1.constructor) returns true'
+);
+
+assert.sameValue(
+  Function.prototype.isPrototypeOf(Error.constructor),
+  true,
+  'Function.prototype.isPrototypeOf(Error.constructor) returns true'
+);

+ 24 - 0
Jint.Tests.Test262/test/built-ins/Error/is-a-constructor.js

@@ -0,0 +1,24 @@
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-ecmascript-standard-built-in-objects
+description: >
+  The Error constructor implements [[Construct]]
+info: |
+  IsConstructor ( argument )
+
+  The abstract operation IsConstructor takes argument argument (an ECMAScript language value).
+  It determines if argument is a function object with a [[Construct]] internal method.
+  It performs the following steps when called:
+
+  If Type(argument) is not Object, return false.
+  If argument has a [[Construct]] internal method, return true.
+  Return false.
+includes: [isConstructor.js]
+features: [Reflect.construct]
+---*/
+
+assert.sameValue(isConstructor(Error), true, 'isConstructor(Error) must return true');
+new Error();
+  

+ 12 - 0
Jint.Tests.Test262/test/built-ins/Error/length.js

@@ -0,0 +1,12 @@
+// Copyright 2009 the Sputnik authors.  All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+info: The length property value is 1
+es5id: 15.11.3_A2_T1
+description: Checking length property
+---*/
+
+var err1 = Error("err");
+assert.sameValue(err1.constructor.length, 1, 'The value of err1.constructor.length is 1');
+assert.sameValue(Error.constructor.length, 1, 'The value of Error.constructor.length is 1');

+ 11 - 0
Jint.Tests.Test262/test/built-ins/Error/name.js

@@ -0,0 +1,11 @@
+// Copyright (C) 2020 Rick Waldron.  All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-error.prototype.name
+description: >
+  The initial value of Error.prototype.name is "Error".
+---*/
+
+assert.sameValue(Error.prototype.name, 'Error');
+

+ 16 - 0
Jint.Tests.Test262/test/built-ins/Error/prop-desc.js

@@ -0,0 +1,16 @@
+// Copyright (C) 2019 Bocoup. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-constructor-properties-of-the-global-object-error
+description: Property descriptor for Error
+info: |
+  Every other data property described in clauses 18 through 26 and in Annex B.2
+  has the attributes { [[Writable]]: true, [[Enumerable]]: false,
+  [[Configurable]]: true } unless otherwise specified.
+includes: [propertyHelper.js]
+---*/
+
+verifyNotEnumerable(this, "Error");
+verifyWritable(this, "Error");
+verifyConfigurable(this, "Error");

+ 0 - 1
Jint.Tests.Test262/test/built-ins/Error/proto-from-ctor-realm.js

@@ -2,7 +2,6 @@
 // This code is governed by the BSD license found in the LICENSE file.
 /*---
 esid: sec-error-message
-es6id: 19.5.1.1
 description: Default [[Prototype]] value derived from realm of the newTarget
 info: |
     [...]

+ 7 - 5
Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.3.1_A1_T1.js

@@ -13,11 +13,11 @@ var proto = Error.prototype;
 //CHECK#1
 verifyNotConfigurable(Error, "prototype");
 try {
-  if ((delete Error.prototype) !== false) {
-    $ERROR('#1: Error.prototype has the attribute DontDelete');
-  }
+  assert.sameValue(delete Error.prototype, false);
 } catch (e) {
-  if (e instanceof Test262Error) throw e;
+  if (e instanceof Test262Error) {
+    throw e;
+  }
   assert(e instanceof TypeError);
 }
 //
@@ -26,7 +26,9 @@ try {
 //////////////////////////////////////////////////////////////////////////////
 //CHECK#2
 if (Error.prototype !== proto) {
-  $ERROR('#2: var proto=Error.prototype; delete Error.prototype; Error.prototype===proto. Actual: ' + Error.prototype);
+  throw new Test262Error('#2: var proto=Error.prototype; delete Error.prototype; Error.prototype===proto. Actual: ' + Error.prototype);
 }
 //
 //////////////////////////////////////////////////////////////////////////////
+
+// TODO: Convert to verifyProperty() format.

+ 11 - 19
Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.3.1_A2_T1.js

@@ -6,21 +6,13 @@ info: Error.prototype property has the attributes {DontEnum}
 es5id: 15.11.3.1_A2_T1
 description: Checking if enumerating the Error.prototype property fails
 ---*/
+assert(Error.hasOwnProperty('prototype'), 'Error.hasOwnProperty(\'prototype\') must return true');
 
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#0
-if (!(Error.hasOwnProperty('prototype'))) {
-  $ERROR('#0: Error.hasOwnProperty(\'prototype\') return true. Actual: ' + Error.hasOwnProperty('prototype'));
-}
-//
-//////////////////////////////////////////////////////////////////////////////
-
+assert(
+  !Error.propertyIsEnumerable('prototype'),
+  'The value of !Error.propertyIsEnumerable(\'prototype\') is expected to be true'
+);
 
-//////////////////////////////////////////////////////////////////////////////
-// CHECK#1
-if (Error.propertyIsEnumerable('prototype')) {
-  $ERROR('#1: Error.propertyIsEnumerable(\'prototype\') return false. Actual: ' + Error.propertyIsEnumerable('prototype'));
-}
 //
 //////////////////////////////////////////////////////////////////////////////
 
@@ -30,11 +22,11 @@ if (Error.propertyIsEnumerable('prototype')) {
 var cout = 0;
 
 for (var p in Error) {
-  if (p === "prototype") cout++;
+  if (p === "prototype") {
+    cout++;
+  }
 }
 
-if (cout !== 0) {
-  $ERROR('#2: cout === 0. Actual: ' + cout);
-}
-//
-//////////////////////////////////////////////////////////////////////////////
+assert.sameValue(cout, 0, 'The value of cout is expected to be 0');
+
+// TODO: Convert to verifyProperty() format.

+ 4 - 25
Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.3.1_A3_T1.js

@@ -7,14 +7,7 @@ es5id: 15.11.3.1_A3_T1
 description: Checking if varying the Error.prototype property fails
 includes: [propertyHelper.js]
 ---*/
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-if (!(Error.hasOwnProperty('prototype'))) {
-  $ERROR('#1: Error.hasOwnProperty(\'prototype\') return true. Actual: ' + Error.hasOwnProperty('prototype'));
-}
-//
-//////////////////////////////////////////////////////////////////////////////
+assert(Error.hasOwnProperty('prototype'));
 
 var __obj = Error.prototype;
 
@@ -22,21 +15,7 @@ verifyNotWritable(Error, "prototype", null, function() {
   return "shifted";
 });
 
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#2
-if (Error.prototype !== __obj) {
-  $ERROR('#2: __obj = Error.prototype; Error.prototype = function(){return "shifted";}; Error.prototype === __obj. Actual: ' + Error.prototype);
-}
-//
-//////////////////////////////////////////////////////////////////////////////
+assert.sameValue(Error.prototype, __obj);
+
+// TODO: Convert to verifyProperty() format.
 
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#3
-try {
-  Error.prototype();
-  $ERROR('#3: "Error.prototype()" lead to throwing exception');
-} catch (e) {
-  if (e instanceof Test262Error) throw e;
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 1 - 8
Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.3.1_A4_T1.js

@@ -6,11 +6,4 @@ info: The Error has property prototype
 es5id: 15.11.3.1_A4_T1
 description: Checking Error.hasOwnProperty('prototype')
 ---*/
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-if (!(Error.hasOwnProperty('prototype'))) {
-  $ERROR('#1: Error.hasOwnProperty(\'prototype\') return true. Actual: ' + Error.hasOwnProperty('prototype'));
-}
-//
-//////////////////////////////////////////////////////////////////////////////
+assert(Error.hasOwnProperty('prototype'), 'Error.hasOwnProperty(\'prototype\') must return true');

+ 4 - 8
Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.4_A1.js

@@ -8,11 +8,7 @@ info: |
 es5id: 15.11.4_A1
 description: Get Error.prototype and compare with Object.prototype
 ---*/
-
-//////////////////////////////////////////////////////////////////////////////
-// CHECK#1
-if (!Object.prototype.isPrototypeOf(Error.prototype)) {
-  $ERROR('#1: Object.prototype.isPrototypeOf(Error.prototype) return true. Actual: ' + Object.prototype.isPrototypeOf(Error.prototype));
-}
-//
-//////////////////////////////////////////////////////////////////////////////
+assert(
+  Object.prototype.isPrototypeOf(Error.prototype),
+  'Object.prototype.isPrototypeOf(Error.prototype) must return true'
+);

+ 1 - 7
Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.4_A2.js

@@ -14,10 +14,4 @@ description: >
 Error.prototype.toString = Object.prototype.toString;
 var __tostr = Error.prototype.toString();
 
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-if (__tostr !== "[object Object]") {
-  $ERROR('#1: Error.prototype.toString=Object.prototype.toString; __tostr = Error.prototype.toString(); __tostr === "[object Object]". Actual: ' + __tostr);
-}
-//
-//////////////////////////////////////////////////////////////////////////////
+assert.sameValue(__tostr, "[object Object]", 'The value of __tostr is expected to be "[object Object]"');

+ 3 - 9
Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.4_A3.js

@@ -7,13 +7,7 @@ es5id: 15.11.4_A3
 description: Checking if call of Error prototype as a function fails
 ---*/
 
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-try {
+assert.throws(TypeError, () => {
   Error.prototype();
-  $ERROR('#1: "Error.prototype()" lead to throwing exception');
-} catch (e) {
-  if (e instanceof Test262Error) throw e;
-}
-//
-//////////////////////////////////////////////////////////////////////////////
+  throw new Test262Error();
+});

+ 4 - 10
Jint.Tests.Test262/test/built-ins/Error/prototype/S15.11.4_A4.js

@@ -7,13 +7,7 @@ es5id: 15.11.4_A4
 description: Checking if creating "new Error.prototype" fails
 ---*/
 
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-try {
-  var __instance = new Error.prototype;
-  $ERROR('#1: "var __instance = new Error.prototype" lead to throwing exception');
-} catch (e) {
-  if (e instanceof Test262Error) throw e;
-}
-//
-//////////////////////////////////////////////////////////////////////////////
+assert.throws(TypeError, () => {
+  new Error.prototype();
+  throw new Test262Error();
+});

+ 0 - 18
Jint.Tests.Test262/test/built-ins/Error/prototype/constructor/S15.11.4.1_A1_T1.js

@@ -1,18 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: |
-    The initial value of Error.prototype.constructor is the built-in Error
-    constructor
-es5id: 15.11.4.1_A1_T1
-description: Checking Error.prototype.constructor
----*/
-
-//////////////////////////////////////////////////////////////////////////////
-//CHECK#1
-if (Error.prototype.constructor !== Error) {
-  $ERROR('#1: Error.prototype.constructor === Error. Actual: ' + Error.prototype.constructor);
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 5 - 35
Jint.Tests.Test262/test/built-ins/Error/prototype/constructor/S15.11.4.1_A1_T2.js

@@ -15,44 +15,14 @@ var constr = Error.prototype.constructor;
 
 var err = new constr;
 
-//////////////////////////////////////////////////////////////////////////////
-// CHECK#0
-if (err === undefined) {
-  $ERROR('#0: constr = Error.prototype.constructor; err = new constr; err === undefined');
-}
-//
-//////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////
-// CHECK#1
-if (err.constructor !== Error) {
-  $ERROR('#1: constr = Error.prototype.constructor; err = new constr; err.constructor === Error. Actual: ' + err.constructor);
-}
-//
-//////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////
-// CHECK#2
-if (!(Error.prototype.isPrototypeOf(err))) {
-  $ERROR('#2: constr = Error.prototype.constructor; err = new constr; Error.prototype.isPrototypeOf(err) return true. Actual: ' + Error.prototype.isPrototypeOf(err));
-}
+assert.notSameValue(err, undefined, 'The value of err is expected to not equal ``undefined``');
+assert.sameValue(err.constructor, Error, 'The value of err.constructor is expected to equal the value of Error');
+assert(Error.prototype.isPrototypeOf(err), 'Error.prototype.isPrototypeOf(err) must return true');
 //
 //////////////////////////////////////////////////////////////////////////////
 
 //////////////////////////////////////////////////////////////////////////////
 // CHECK#3
 Error.prototype.toString = Object.prototype.toString;
-var to_string_result = '[object ' + 'Error' + ']';
-if (err.toString() !== to_string_result) {
-  $ERROR('#3: constr = Error.prototype.constructor; err = new constr; Error.prototype.toString=Object.prototype.toString; err.toString() === \'[object Error]\'. Actual: ' + err.toString());
-}
-//
-//////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////
-// CHECK#4
-if (err.valueOf().toString() !== to_string_result) {
-  $ERROR('#4: constr = Error.prototype.constructor; err = new constr; Error.prototype.toString=Object.prototype.toString; err.valueOf().toString() === \'[object Error]\'. Actual: ' + err.valueOf().toString());
-}
-//
-//////////////////////////////////////////////////////////////////////////////
+assert.sameValue(err.toString(), '[object Error]', 'err.toString() must return "[object Error]"');
+assert.sameValue(err.valueOf().toString(), '[object Error]', 'err.valueOf().toString() must return "[object Error]"');

+ 14 - 0
Jint.Tests.Test262/test/built-ins/Error/prototype/constructor/prop-desc.js

@@ -0,0 +1,14 @@
+// Copyright (c) 2021 the V8 project authors.  All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-error.prototype.constructor
+description: Property descriptor of Error.prototype.constructor
+includes: [propertyHelper.js]
+---*/
+
+verifyProperty(Error.prototype, 'constructor', {
+  enumerable: false,
+  writable: true,
+  configurable: true,
+  value: Error
+});

+ 0 - 11
Jint.Tests.Test262/test/built-ins/Error/prototype/message/15.11.4.3-1.js

@@ -1,11 +0,0 @@
-// Copyright (c) 2012 Ecma International.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-es5id: 15.11.4.3-1
-description: Error.prototype.message is not enumerable.
----*/
-
-for (var i in Error.prototype) {
-  assert.notSameValue(i, "message", 'i');
-}

+ 0 - 16
Jint.Tests.Test262/test/built-ins/Error/prototype/message/S15.11.4.3_A1.js

@@ -1,16 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: The Error.prototype has message property
-es5id: 15.11.4.3_A1
-description: Checking Error.prototype.message
----*/
-
-//////////////////////////////////////////////////////////////////////////////
-// CHECK#1
-if (!Error.prototype.hasOwnProperty('message')) {
-  $ERROR('#1: Error.prototype.hasOwnProperty(\'message\') reurn true. Actual: ' + Error.prototype.hasOwnProperty('message'));
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 0 - 16
Jint.Tests.Test262/test/built-ins/Error/prototype/message/S15.11.4.3_A2.js

@@ -1,16 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: The initial value of Error.prototype.message is ""
-es5id: 15.11.4.3_A2
-description: Checking value of Error.prototype.message
----*/
-
-//////////////////////////////////////////////////////////////////////////////
-// CHECK#1
-if (typeof Error.prototype.message !== "string") {
-  $ERROR('#1: typeof Error.prototype.message === "string". Actual: ' + Error.prototype.message);
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 14 - 0
Jint.Tests.Test262/test/built-ins/Error/prototype/message/prop-desc.js

@@ -0,0 +1,14 @@
+// Copyright (c) 2021 the V8 project authors.  All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-error.prototype.message
+description: Property descriptor of Error.prototype.message
+includes: [propertyHelper.js]
+---*/
+
+verifyProperty(Error.prototype, 'message', {
+  enumerable: false,
+  writable: true,
+  configurable: true,
+  value: ''
+});

+ 0 - 11
Jint.Tests.Test262/test/built-ins/Error/prototype/name/15.11.4.2-1.js

@@ -1,11 +0,0 @@
-// Copyright (c) 2012 Ecma International.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-es5id: 15.11.4.2-1
-description: Error.prototype.name is not enumerable.
----*/
-
-for (var i in Error.prototype) {
-  assert.notSameValue(i, "name", 'i');
-}

+ 0 - 16
Jint.Tests.Test262/test/built-ins/Error/prototype/name/S15.11.4.2_A1.js

@@ -1,16 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: The Error.prototype has name property
-es5id: 15.11.4.2_A1
-description: Checking Error.prototype.name
----*/
-
-//////////////////////////////////////////////////////////////////////////////
-// CHECK#1
-if (!Error.prototype.hasOwnProperty('name')) {
-  $ERROR('#1: Error.prototype.hasOwnProperty(\'name\') return true. Actual: ' + Error.prototype.hasOwnProperty('name'));
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 0 - 16
Jint.Tests.Test262/test/built-ins/Error/prototype/name/S15.11.4.2_A2.js

@@ -1,16 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: The initial value of Error.prototype.name is "Error"
-es5id: 15.11.4.2_A2
-description: Checking value of Error.prototype.name
----*/
-
-//////////////////////////////////////////////////////////////////////////////
-// CHECK#1
-if (Error.prototype.name !== "Error") {
-  $ERROR('#1: Error.prototype.name==="Error". Actual: ' + Error.prototype.name);
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 14 - 0
Jint.Tests.Test262/test/built-ins/Error/prototype/name/prop-desc.js

@@ -0,0 +1,14 @@
+// Copyright (c) 2021 the V8 project authors.  All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-error.prototype.name
+description: Property descriptor of Error.prototype.name
+includes: [propertyHelper.js]
+---*/
+
+verifyProperty(Error.prototype, 'name', {
+  enumerable: false,
+  writable: true,
+  configurable: true,
+  value: 'Error'
+});

+ 34 - 0
Jint.Tests.Test262/test/built-ins/Error/prototype/no-error-data.js

@@ -0,0 +1,34 @@
+// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-properties-of-the-error-prototype-object
+description: >
+  The Error Prototype object does not have a [[ErrorData]] internal slot.
+info: |
+  Properties of the Error Prototype Object
+
+  The Error prototype object:
+  [...]
+  * is not an Error instance and does not have an [[ErrorData]] internal slot.
+
+  Object.prototype.toString ( )
+
+  [...]
+  8. Else if O has an [[ErrorData]] internal slot, let builtinTag be "Error".
+  [...]
+  15. Let tag be ? Get(O, @@toStringTag).
+  16. If Type(tag) is not String, set tag to builtinTag.
+  17. Return the string-concatenation of "[object ", tag, and "]".
+features: [Symbol.toStringTag]
+---*/
+
+// Although the spec doesn't define Error.prototype[@@toStringTag], set it
+// to non-string anyway because implementations are allowed to define it.
+Object.defineProperty(Error.prototype, Symbol.toStringTag, {
+  value: null,
+});
+
+assert.sameValue(
+  Object.prototype.toString.call(Error.prototype),
+  "[object Object]"
+);

+ 2 - 2
Jint.Tests.Test262/test/built-ins/Error/prototype/toString/15.11.4.4-8-2.js

@@ -11,8 +11,8 @@ description: >
 var errObj = new Error();
 errObj.name = "";
 if (errObj.name !== "") {
-  $ERROR("Expected errObj.name to be '', actually " + errObj.name);
+  throw new Test262Error("Expected errObj.name to be '', actually " + errObj.name);
 }
 if (errObj.toString() !== "") {
-  $ERROR("Expected errObj.toString() to be '', actually " + errObj.toString());
+  throw new Test262Error("Expected errObj.toString() to be '', actually " + errObj.toString());
 }

+ 0 - 16
Jint.Tests.Test262/test/built-ins/Error/prototype/toString/S15.11.4.4_A1.js

@@ -1,16 +0,0 @@
-// Copyright 2009 the Sputnik authors.  All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-info: The Error.prototype has toString property
-es5id: 15.11.4.4_A1
-description: Checking Error.prototype.toString
----*/
-
-//////////////////////////////////////////////////////////////////////////////
-// CHECK#1
-if (!Error.prototype.hasOwnProperty('toString')) {
-  $ERROR('#1: Error.prototype.hasOwnProperty(\'toString\') return true. Actual: ' + Error.prototype.hasOwnProperty('toString'));
-}
-//
-//////////////////////////////////////////////////////////////////////////////

+ 2 - 15
Jint.Tests.Test262/test/built-ins/Error/prototype/toString/S15.11.4.4_A2.js

@@ -4,20 +4,7 @@
 /*---
 info: The Error.prototype.toString returns an implementation defined string
 es5id: 15.11.4.4_A2
-description: Checking if call of Error.prototype.toSting() fails
+description: Checking if call of Error.prototype.toString() fails
 ---*/
 
-//////////////////////////////////////////////////////////////////////////////
-// CHECK#1
-var err1 = new Error("Error");
-try {
-  var toStr = err1.toString();
-}
-catch (e) {
-  $ERROR('#1: var err1=new Error("Error"); var toStr=err1.toString(); lead to throwing exception. Exception is ' + e);
-}
-if (toStr === undefined) {
-  $ERROR('#2: var err1=new Error("Error"); var toStr=err1.toString(); toStr!==undefined. Actual: ' + toStr);
-}
-//
-//////////////////////////////////////////////////////////////////////////////
+assert.notSameValue(new Error("Error").toString(), undefined, 'The value of toStr is expected to not equal ``undefined``');

+ 32 - 0
Jint.Tests.Test262/test/built-ins/Error/prototype/toString/called-as-function.js

@@ -0,0 +1,32 @@
+// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-error.prototype.tostring
+description: >
+    `this` value is resolved using strict mode semantics,
+    throwing TypeError if called as top-level function.
+info: |
+    Error.prototype.toString ( )
+
+    1. Let O be the this value.
+    2. If Type(O) is not Object, throw a TypeError exception.
+
+    ToObject ( argument )
+
+    Argument Type: Undefined
+    Result: Throw a TypeError exception.
+---*/
+
+["name", "message"].forEach(function(key) {
+    Object.defineProperty(this, key, {
+        get: function() {
+            throw new Test262Error(key + " lookup should not be performed");
+        },
+    });
+}, this);
+
+var toString = Error.prototype.toString;
+assert.throws(TypeError, function() {
+    toString();
+});

+ 18 - 0
Jint.Tests.Test262/test/built-ins/Error/prototype/toString/invalid-receiver.js

@@ -0,0 +1,18 @@
+// Copyright (C) 2019 Ecma International. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-error.prototype.tostring
+description: >
+  Error.prototype.toString throws if its receiver is not an object.
+info: |
+  Error.prototype.toString ( )
+  1. Let O be this value.
+  2. If Type(O) is not Object, throw a TypeError exception.
+---*/
+
+[undefined, null, 1, true, 'string', Symbol()].forEach((v) => {
+  assert.throws(TypeError, () => {
+    Error.prototype.toString.call(v);
+  }, `Error.prototype.toString.call(${String(v)})`);
+});

+ 33 - 0
Jint.Tests.Test262/test/built-ins/Error/prototype/toString/not-a-constructor.js

@@ -0,0 +1,33 @@
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-ecmascript-standard-built-in-objects
+description: >
+  Error.prototype.toString does not implement [[Construct]], is not new-able
+info: |
+  ECMAScript Function Objects
+
+  Built-in function objects that are not identified as constructors do not
+  implement the [[Construct]] internal method unless otherwise specified in
+  the description of a particular function.
+
+  sec-evaluatenew
+
+  ...
+  7. If IsConstructor(constructor) is false, throw a TypeError exception.
+  ...
+includes: [isConstructor.js]
+features: [Reflect.construct, arrow-function]
+---*/
+
+assert.sameValue(
+  isConstructor(Error.prototype.toString),
+  false,
+  'isConstructor(Error.prototype.toString) must return false'
+);
+
+assert.throws(TypeError, () => {
+  new Error.prototype.toString();
+}, '`new Error.prototype.toString()` throws TypeError');
+

+ 13 - 0
Jint.Tests.Test262/test/built-ins/Error/prototype/toString/prop-desc.js

@@ -0,0 +1,13 @@
+// Copyright (c) 2021 the V8 project authors.  All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-error.prototype.toString
+description: Property descriptor of Error.prototype.toString
+includes: [propertyHelper.js]
+---*/
+
+verifyProperty(Error.prototype, 'toString', {
+  enumerable: false,
+  writable: true,
+  configurable: true,
+});

+ 20 - 0
Jint.Tests.Test262/test/built-ins/Error/prototype/toString/undefined-props.js

@@ -0,0 +1,20 @@
+// Copyright (C) 2019 Ecma International. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-error.prototype.tostring
+description: >
+  Error.prototype.toString handles this.name and this.message being undefined.
+info: |
+  Error.prototype.toString ( )
+  ...
+  3. Let name be ? Get(O, "name").
+  4. If name is undefined, set name to "Error"; otherwise set name to ? ToString(name).
+  5. Let msg be ? Get(O, "message").
+  6. If msg is undefined, set msg to the empty String; otherwise set msg to ? ToString(msg).
+---*/
+
+assert.sameValue(Error.prototype.toString.call({}), 'Error');
+assert.sameValue(Error.prototype.toString.call({ message: '42' }), 'Error: 42');
+assert.sameValue(Error.prototype.toString.call({ name: '24' }), '24');
+assert.sameValue(Error.prototype.toString.call({ name: '24', message: '42' }), '24: 42');

+ 13 - 0
Jint.Tests.Test262/test/built-ins/Error/the-initial-value-of-errorprototypemessage-is-the-empty-string.js

@@ -0,0 +1,13 @@
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-error.prototype.message
+description: The initial value of Error.prototype.message is the empty String.
+---*/
+
+assert.sameValue(Error('a').message, "a", 'The value of err1.message is "a"');
+assert.sameValue(new Error('a').message, "a", 'The value of err1.message is "a"');
+assert(!Error().hasOwnProperty('message'));
+assert(!new Error().hasOwnProperty('message'));
+assert.sameValue(new Error().message, Error.prototype.message, 'The value of new Error().message equals Error.prototype.message');

+ 13 - 0
Jint.Tests.Test262/test/built-ins/Error/tostring-1.js

@@ -0,0 +1,13 @@
+// Copyright (C) 2020 Rick Waldron.  All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-object.prototype.tostring
+description: >
+    Else if O has an [[ErrorData]] internal slot, let builtinTag be "Error".
+---*/
+assert.sameValue(new Error().toString(), 'Error', 'new Error.toString() returns "Error"');
+
+Error.prototype.toString = Object.prototype.toString;
+assert.sameValue(new Error().toString(), '[object Error]', 'new Error.toString() returns "[object Error]" (Object.prototype.toString)');
+

+ 21 - 0
Jint.Tests.Test262/test/built-ins/Error/tostring-2.js

@@ -0,0 +1,21 @@
+// Copyright (C) 2020 Rick Waldron.  All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-object.prototype.tostring
+description: >
+    Else if O has an [[ErrorData]] internal slot, let builtinTag be "Error".
+---*/
+
+assert.sameValue(
+  Error().toString(),
+  'Error',
+  'Error().toString() returns "Error"'
+);
+
+Error.prototype.toString = Object.prototype.toString;
+assert.sameValue(
+  Error().toString(),
+  '[object Error]',
+  'Error().toString() returns "[object Error]" (Object.prototype.toString)'
+);

+ 12 - 0
Jint.Tests/Runtime/MethodAmbiguityTests.cs

@@ -33,6 +33,8 @@ namespace Jint.Tests.Runtime
 
         public class TestClass
         {
+            public string this[int index] => "int";
+            public string this[string index] => "string";
             public int TestMethod(double a, string b, double c) => 0;
             public int TestMethod(double a, double b, double c) => 1;
             public int TestMethod(TestClass a, string b, double c) => 2;
@@ -71,5 +73,15 @@ namespace Jint.Tests.Runtime
                 equal(7, tc.TestMethod(cc, '', {}));
             ");
         }
+
+        [Fact]
+        public void IndexerCachesMethodsCorrectly()
+        {
+            RunTest(@"
+                var tc = new TestClass();
+                equal('string:int', tc['Whistler'] + ':' + tc[10]);
+                equal('int:string', tc[10] + ':' + tc['Whistler']);
+            ");
+        }
     }
 }

+ 10 - 2
Jint/Native/Error/ErrorConstructor.cs

@@ -41,8 +41,7 @@ namespace Jint.Native.Error
             var o = OrdinaryCreateFromConstructor(
                 newTarget,
                 static intrinsics => intrinsics.Error.PrototypeObject,
-                static (engine, realm, state) => new ErrorInstance(engine, (JsString) state),
-                _name);
+                static (engine, realm, state) => new ErrorInstance(engine));
 
             var jsValue = arguments.At(0);
             if (!jsValue.IsUndefined())
@@ -57,6 +56,15 @@ namespace Jint.Native.Error
             var stackDesc = new PropertyDescriptor(stackString, PropertyFlag.NonEnumerable);
             o.DefinePropertyOrThrow(CommonProperties.Stack, stackDesc);
 
+            var options = arguments.At(1);
+
+            if (options is ObjectInstance oi && oi.HasProperty("cause"))
+            {
+                var cause = oi.Get("cause");
+                var causeDesc = new PropertyDescriptor(cause, PropertyFlag.NonEnumerable);
+                o.DefinePropertyOrThrow("cause", causeDesc);
+            }
+
             return o;
         }
     }

+ 0 - 15
Jint/Native/Error/ErrorInstance.cs

@@ -1,30 +1,15 @@
 using Jint.Native.Object;
 using Jint.Runtime;
-using Jint.Runtime.Descriptors;
 
 namespace Jint.Native.Error
 {
     public class ErrorInstance : ObjectInstance
     {
-        private readonly JsString _name;
-        private PropertyDescriptor _descriptor;
-
         internal ErrorInstance(
             Engine engine,
-            JsString name,
             ObjectClass objectClass = ObjectClass.Error)
             : base(engine, objectClass)
         {
-            _name = name;
-        }
-
-        public override PropertyDescriptor GetOwnProperty(JsValue property)
-        {
-            if (property == CommonProperties.Name)
-            {
-                return _descriptor ??= new PropertyDescriptor(_name, PropertyFlag.Configurable | PropertyFlag.Writable);
-            };
-            return base.GetOwnProperty(property);
         }
 
         public override string ToString()

+ 8 - 11
Jint/Native/Error/ErrorPrototype.cs

@@ -11,6 +11,7 @@ namespace Jint.Native.Error
     /// </summary>
     public sealed class ErrorPrototype : ErrorInstance
     {
+        private readonly JsString _name;
         private readonly Realm _realm;
         private readonly ErrorConstructor _constructor;
 
@@ -21,9 +22,10 @@ namespace Jint.Native.Error
             ObjectInstance prototype,
             JsString name,
             ObjectClass objectClass)
-            : base(engine, name, objectClass)
+            : base(engine, objectClass)
         {
             _realm = realm;
+            _name = name;
             _constructor = constructor;
             _prototype = prototype;
         }
@@ -34,6 +36,7 @@ namespace Jint.Native.Error
             {
                 ["constructor"] = new PropertyDescriptor(_constructor, PropertyFlag.NonEnumerable),
                 ["message"] = new PropertyDescriptor("", PropertyFlag.Configurable | PropertyFlag.Writable),
+                ["name"] = new PropertyDescriptor(_name, PropertyFlag.Configurable | PropertyFlag.Writable),
                 ["toString"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "toString", ToString, 0, PropertyFlag.Configurable), PropertyFlag.Configurable | PropertyFlag.Writable)
             };
             SetProperties(properties);
@@ -47,18 +50,12 @@ namespace Jint.Native.Error
                 ExceptionHelper.ThrowTypeError(_realm);
             }
 
-            var name = TypeConverter.ToString(o.Get("name", this));
+            var nameProp = o.Get("name", this);
+            var name = nameProp.IsUndefined() ? "Error" : TypeConverter.ToString(nameProp);
 
             var msgProp = o.Get("message", this);
-            string msg;
-            if (msgProp.IsUndefined())
-            {
-                msg = "";
-            }
-            else
-            {
-                msg = TypeConverter.ToString(msgProp);
-            }
+            string msg = msgProp.IsUndefined() ? "" : TypeConverter.ToString(msgProp);
+
             if (name == "")
             {
                 return msg;