|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * Tests of Object/Array.prototype.toString on proxy objects. |
| 10 | + */ |
| 11 | + |
| 12 | +load('assert.js'); |
| 13 | + |
| 14 | +// Ensure that Array.prototype.toString invokes Object.prototype.toString |
| 15 | +delete Array.prototype.join; |
| 16 | + |
| 17 | +[Object.prototype.toString, Array.prototype.toString].forEach(function (testedFunction) { |
| 18 | + // Proxy does not inherit [[ParameterMap]], [[ErrorData]], [[BooleanData]], |
| 19 | + // [[NumberData]], [[StringData]], [[DateValue]] and [[RegExpMatcher]] internal slots |
| 20 | + var argumentsObject = (function() { return arguments; })(); |
| 21 | + assertSame('[object Object]', testedFunction.call(new Proxy(argumentsObject, {}))); |
| 22 | + assertSame('[object Object]', testedFunction.call(new Proxy(new Error(), {}))); |
| 23 | + assertSame('[object Object]', testedFunction.call(new Proxy(Object(true), {}))); |
| 24 | + assertSame('[object Object]', testedFunction.call(new Proxy(Object(42), {}))); |
| 25 | + assertSame('[object Object]', testedFunction.call(new Proxy(Object('foo'), {}))); |
| 26 | + assertSame('[object Object]', testedFunction.call(new Proxy(new Date(), {}))); |
| 27 | + assertSame('[object Object]', testedFunction.call(new Proxy(/a/, {}))); |
| 28 | + |
| 29 | + // Proxy inherits [[Call]] internal slot |
| 30 | + assertSame('[object Function]', testedFunction.call(new Proxy(function() {}, {}))); |
| 31 | + |
| 32 | + // There is an explicit handling of array Proxy targets in Object.prototype.toString |
| 33 | + assertSame('[object Array]', testedFunction.call(new Proxy([], {}))); |
| 34 | + // revoked |
| 35 | + var revocable = Proxy.revocable([], {}); |
| 36 | + revocable.revoke(); |
| 37 | + assertThrows(function() { |
| 38 | + testedFunction.call(revocable.proxy); |
| 39 | + }, TypeError); |
| 40 | + // revoked too late (after builtinTag was determined) |
| 41 | + revocable = Proxy.revocable([], { |
| 42 | + get: function (target, key, receiver) { |
| 43 | + if (key === Symbol.toStringTag) { |
| 44 | + revocable.revoke(); |
| 45 | + return undefined; |
| 46 | + } else { |
| 47 | + return Reflect.get(target, key, receiver); |
| 48 | + } |
| 49 | + }, |
| 50 | + }); |
| 51 | + assertSame('[object Array]', testedFunction.call(revocable.proxy)); |
| 52 | +}); |
0 commit comments