Make tamed properties non-enumerable
MODIFY
packages/tame-global-date-object/src/main.js
packages/tame-global-date-object/src/main.js
/* globals globalThis */
-const {
- defineProperties,
- defineProperty,
- getOwnPropertyDescriptors,
- getOwnPropertyDescriptor,
-} = Object;
+const { defineProperties, getOwnPropertyDescriptors } = Object;
export default function tameGlobalDateObject() {
// Capture the original constructor.
const unsafeDate = Date; // TODO freeze
+ // Tame the %Date% and %DatePrototype% intrinsic.
+ const { now } = {
+ now() {
+ return NaN;
+ },
+ };
+ unsafeDate.now = now;
+
+ const { toLocaleString: toLocaleString1 } = {
+ toLocaleString() {
+ return NaN;
+ },
+ };
+ unsafeDate.prototype.toLocaleString = toLocaleString1;
+
// Date(anything) gives a string with the current time
// new Date(x) coerces x into a number and then returns a Date
// new Date() returns the current time, as a Date object
// new Date(undefined) returns a Date object which stringifies to 'Invalid Date'
- // Tame Date constructor.
+ // Tame the Date constructor.
const safeDate = function Date() {
if (new.target === undefined) {
// We were not called as a constructor
@@ -33,38 +43,24 @@ export default function tameGlobalDateObject() {
};
// Copy static properties.
- const safeDateDescs = getOwnPropertyDescriptors({
- now() {
- return NaN;
- },
- });
-
const dateDescs = getOwnPropertyDescriptors(unsafeDate);
- dateDescs.now = safeDateDescs.now;
defineProperties(safeDate, dateDescs);
// Copy prototype properties.
- const safeDatePrototypeDescs = getOwnPropertyDescriptors({
- toLocaleString() {
- return NaN;
- },
- });
- const datePrototypeDescs = getOwnPropertyDescriptors(
- unsafeDate.prototype,
- );
+ const datePrototypeDescs = getOwnPropertyDescriptors(unsafeDate.prototype);
datePrototypeDescs.constructor.value = safeDate;
- datePrototypeDescs.toLocaleString = safeDatePrototypeDescs.toLocaleString;
defineProperties(safeDate.prototype, datePrototypeDescs);
// Done with Date
globalThis.Date = safeDate;
- // eslint-disable-next-line no-extend-native
- const safeObjectPrototypeDescs = getOwnPropertyDescriptors({
+ // Tame the %ObjectPrototype% intrinsic.
+ const { toLocaleString: toLocaleString2 } = {
toLocaleString() {
- throw new Error('suppressed');
+ throw new Error('Object.prototype.toLocaleString is suppressed');
},
- });
+ };
- defineProperties(Object.prototype, safeObjectPrototypeDescs);
+ // eslint-disable-next-line no-extend-native
+ Object.prototype.toLocaleString = toLocaleString2;
}

MODIFY
packages/tame-global-math-object/src/main.js
packages/tame-global-math-object/src/main.js
-const { defineProperties, getOwnPropertyDescriptors } = Object;
-
export default function tameGlobalMathObject() {
- const safeMathDescs = getOwnPropertyDescriptors({
+ // Tame the %Math% intrinsic.
+ const { random } = {
random() {
throw Error('disabled');
},
- });
+ };
- defineProperties(Math, {
- random: {
- value: safeMathDescs.random.value,
- enumerable: false,
- configurable: true,
- writable: true,
- },
- });
+ Math.random = random;
}

MODIFY
packages/tame-global-regexp-object/src/main.js
packages/tame-global-regexp-object/src/main.js
/* globals globalThis */
const {
defineProperties,
- defineProperty,
getOwnPropertyDescriptors,
getOwnPropertyDescriptor,
} = Object;
-const { ownkeys } = Reflect;
-
export default function tameGlobalRegExpObject() {
// Capture the original constructor.
const unsafeRegExp = RegExp; // TODO freeze

MODIFY
packages/tame-global-regexp-object/test262/test262-run.js
packages/tame-global-regexp-object/test262/test262-run.js
@@ -6,33 +6,24 @@ test262Runner({
testDirs: ['/test/built-ins/RegExp'],
excludePaths: [
'test/built-ins/RegExp/property-escapes/', // TODO refine
+ 'test/built-ins/RegExp/match-indices/', // TODO refine
-
- 'test/built-ins/RegExp/prototype/test/S15.10.6.3_A9.js',
- 'test/built-ins/RegExp/unicode_restricted_brackets.js',
- 'test/built-ins/RegExp/unicode_restricted_identity_escape.js',
- 'test/built-ins/RegExp/unicode_restricted_identity_escape_c.js',
- 'test/built-ins/RegExp/unicode_restricted_identity_escape_u.js',
- 'test/built-ins/RegExp/unicode_restricted_identity_escape_x.js',
- 'test/built-ins/RegExp/unicode_restricted_octal_escape.js',
'test/built-ins/RegExp/call_with_non_regexp_same_constructor.js',
+ 'test/built-ins/RegExp/call_with_regexp_match_falsy.js',
'test/built-ins/RegExp/call_with_regexp_not_same_constructor.js',
- 'test/built-ins/RegExp/match-indices/indices-array-non-unicode-match.js',
- 'test/built-ins/RegExp/match-indices/indices-array-properties.js',
- 'test/built-ins/RegExp/match-indices/indices-array-unicode-match.js',
- 'test/built-ins/RegExp/match-indices/indices-array-unicode-property-names.js',
- 'test/built-ins/RegExp/match-indices/indices-array-unmatched.js',
- 'test/built-ins/RegExp/match-indices/indices-groups-object-..js',
- 'test/built-ins/RegExp/match-indices/indices-groups-object-..js',
- 'test/built-ins/RegExp/match-indices/indices-groups-object-unmatched.js',
- 'test/built-ins/RegExp/match-indices/indices-groups-properties.js',
+ 'test/built-ins/RegExp/from-regexp-like-get-ctor-err.js',
+ 'test/built-ins/RegExp/from-regexp-like-short-circuit.js',
'test/built-ins/RegExp/named-groups/groups-object-subclass-sans.js',
+ 'test/built-ins/RegExp/named-groups/groups-object-subclass.js',
+ 'test/built-ins/RegExp/named-groups/groups-object.js',
'test/built-ins/RegExp/named-groups/non-unicode-property-names.js',
+ 'test/built-ins/RegExp/named-groups/unicode-property-names.js',
'test/built-ins/RegExp/prototype/dotAll/this-val-regexp-prototype.js',
'test/built-ins/RegExp/prototype/flags/this-val-regexp-prototype.js',
'test/built-ins/RegExp/prototype/global/this-val-regexp-prototype.js',
'test/built-ins/RegExp/prototype/ignoreCase/this-val-regexp-prototype.js',
'test/built-ins/RegExp/prototype/multiline/this-val-regexp-prototype.js',
+ 'test/built-ins/RegExp/prototype/S15.10.5.1_A4.js',
'test/built-ins/RegExp/prototype/source/this-val-regexp-prototype.js',
'test/built-ins/RegExp/prototype/sticky/this-val-regexp-prototype.js',
'test/built-ins/RegExp/prototype/Symbol.matchAll/string-tostring.js',
@@ -42,25 +33,8 @@ test262Runner({
'test/built-ins/RegExp/prototype/Symbol.replace/coerce-global.js',
'test/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-this-strict.js',
'test/built-ins/RegExp/prototype/Symbol.split/last-index-exceeds-str-size.js',
+ 'test/built-ins/RegExp/prototype/test/S15.10.6.3_A9.js',
'test/built-ins/RegExp/prototype/unicode/this-val-regexp-prototype.js',
- 'test/built-ins/RegExp/unicode_restricted_character_class_escape.js',
- 'test/built-ins/RegExp/unicode_restricted_identity_escape_alpha.js',
- 'test/built-ins/RegExp/unicode_restricted_incomple_quantifier.js',
- 'test/built-ins/RegExp/unicode_restricted_quantifiable_assertion.js',
- 'test/built-ins/RegExp/unicode_restricted_quantifier_without_atom.js',
-'test/built-ins/RegExp/call_with_regexp_match_falsy.js',
-'test/built-ins/RegExp/from-regexp-like-get-ctor-err.js',
-'test/built-ins/RegExp/from-regexp-like-short-circuit.js',
-'test/built-ins/RegExp/match-indices/indices-array-element.js',
-'test/built-ins/RegExp/match-indices/indices-array-matched.js',
-'test/built-ins/RegExp/match-indices/indices-array.js',
-'test/built-ins/RegExp/match-indices/indices-groups-object.js',
-'test/built-ins/RegExp/match-indices/indices-property.js',
-'test/built-ins/RegExp/named-groups/groups-object-subclass.js',
-'test/built-ins/RegExp/named-groups/groups-object.js',
-'test/built-ins/RegExp/named-groups/unicode-property-names.js',
-'test/built-ins/RegExp/prototype/S15.10.5.1_A4.js',
-'test/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-is-..js',
'test/built-ins/RegExp/S15.10.3.1_A1_T1.js',
'test/built-ins/RegExp/S15.10.3.1_A1_T2.js',
'test/built-ins/RegExp/S15.10.3.1_A1_T3.js',
@@ -78,11 +52,19 @@ test262Runner({
'test/built-ins/RegExp/Symbol.species/return-value.js',
'test/built-ins/RegExp/Symbol.species/symbol-species-name.js',
'test/built-ins/RegExp/Symbol.species/symbol-species.js',
-'test/built-ins/RegExp/match-indices/indices-groups-object-..js',
-
- ],
- excludeDescriptions: [
+ 'test/built-ins/RegExp/unicode_restricted_brackets.js',
+ 'test/built-ins/RegExp/unicode_restricted_character_class_escape.js',
+ 'test/built-ins/RegExp/unicode_restricted_identity_escape.js',
+ 'test/built-ins/RegExp/unicode_restricted_identity_escape_alpha.js',
+ 'test/built-ins/RegExp/unicode_restricted_identity_escape_c.js',
+ 'test/built-ins/RegExp/unicode_restricted_identity_escape_u.js',
+ 'test/built-ins/RegExp/unicode_restricted_identity_escape_x.js',
+ 'test/built-ins/RegExp/unicode_restricted_incomple_quantifier.js',
+ 'test/built-ins/RegExp/unicode_restricted_octal_escape.js',
+ 'test/built-ins/RegExp/unicode_restricted_quantifiable_assertion.js',
+ 'test/built-ins/RegExp/unicode_restricted_quantifier_without_atom.js',
],
+ excludeDescriptions: [],
excludeFeatures: [
'cross-realm', // TODO: Evaluator does not create realms.
],

ADD
packages/test262-runner/test262/harness/compareIterator.js
+// Copyright (C) 2018 Peter Wong. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+description: Compare the values of an iterator with an array of expected values
+defines: [assert.compareIterator]
+---*/
+
+// Example:
+//
+// function* numbers() {
+// yield 1;
+// yield 2;
+// yield 3;
+// }
+//
+// compareIterator(numbers(), [
+// v => assert.sameValue(v, 1),
+// v => assert.sameValue(v, 2),
+// v => assert.sameValue(v, 3),
+// ]);
+//
+assert.compareIterator = function(iter, validators, message) {
+ message = message || '';
+
+ var i, result;
+ for (i = 0; i < validators.length; i++) {
+ result = iter.next();
+ assert(!result.done, 'Expected ' + i + ' values(s). Instead iterator only produced ' + (i - 1) + ' value(s). ' + message);
+ validators[i](result.value);
+ }
+
+ result = iter.next();
+ assert(result.done, 'Expected only ' + i + ' values(s). Instead iterator produced more. ' + message);
+ assert.sameValue(result.value, undefined, 'Expected value of `undefined` when iterator completes. ' + message);
+}

Make tamed properties non-enumerable