diff --git a/packages/core-js/modules/es.symbol.js b/packages/core-js/modules/es.symbol.js index 16955f8d6a22..fed30b850289 100644 --- a/packages/core-js/modules/es.symbol.js +++ b/packages/core-js/modules/es.symbol.js @@ -18,6 +18,7 @@ var enumKeys = require('../internals/enum-keys'); var isArray = require('../internals/is-array'); var anObject = require('../internals/an-object'); var isObject = require('../internals/is-object'); +var toObject = require('../internals/to-object'); var toIndexedObject = require('../internals/to-indexed-object'); var toPrimitive = require('../internals/to-primitive'); var createPropertyDescriptor = require('../internals/create-property-descriptor'); @@ -36,6 +37,7 @@ var getInternalState = InternalStateModule.getterFor(SYMBOL); var nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f; var nativeDefineProperty = definePropertyModule.f; var nativeGetOwnPropertyNames = getOwnPropertyNamesExternal.f; +var nativeGetOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols'); var $Symbol = global.Symbol; var JSON = global.JSON; var nativeJSONStringify = JSON && JSON.stringify; @@ -172,7 +174,7 @@ if (!NATIVE_SYMBOL) { definePropertyModule.f = $defineProperty; getOwnPropertyDescriptorModule.f = $getOwnPropertyDescriptor; require('../internals/object-get-own-property-names').f = getOwnPropertyNamesExternal.f = $getOwnPropertyNames; - require('../internals/object-get-own-property-symbols').f = $getOwnPropertySymbols; + nativeGetOwnPropertySymbolsModule.f = $getOwnPropertySymbols; if (DESCRIPTORS) { // https://github.com/tc39/proposal-Symbol-description @@ -240,6 +242,16 @@ $export({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL }, { getOwnPropertySymbols: $getOwnPropertySymbols }); +// Chome Mobile 38 and 39 getOwnPropertySymbols fails on primitives +// https://bugs.chromium.org/p/v8/issues/detail?id=3443 +var FAILS_ON_PRIMITIVES = fails(function () { return !Object.getOwnPropertySymbols(1); }); + +$export({ target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES }, { + getOwnPropertySymbols: function getOwnPropertySymbols(it) { + return nativeGetOwnPropertySymbolsModule.f(toObject(it)); + } +}); + // `JSON.stringify` method behavior with symbols // https://tc39.github.io/ecma262/#sec-json.stringify JSON && $export({ target: 'JSON', stat: true, forced: !NATIVE_SYMBOL || fails(function () { diff --git a/tests/compat/tests.js b/tests/compat/tests.js index a101cf785dc7..d01e5e104969 100644 --- a/tests/compat/tests.js +++ b/tests/compat/tests.js @@ -158,6 +158,7 @@ function createStringTrimMethodTest(METHOD_NAME) { GLOBAL.tests = { 'es.symbol': [SYMBOLS_SUPPORT, function () { return Object.getOwnPropertySymbols + && Object.getOwnPropertySymbols('qwe') && Symbol['for'] && Symbol.keyFor && JSON.stringify([Symbol()]) == '[null]' diff --git a/tests/pure/es.symbol.js b/tests/pure/es.symbol.js index ea5e50024115..215ce5c8d16d 100644 --- a/tests/pure/es.symbol.js +++ b/tests/pure/es.symbol.js @@ -85,6 +85,10 @@ QUnit.test('Object.getOwnPropertySymbols', assert => { assert.deepEqual(getOwnPropertyNames(object).sort(), ['a', 'd', 's']); assert.strictEqual(getOwnPropertySymbols(object).length, 1); assert.strictEqual(getOwnPropertySymbols(Object.prototype).length, 0); + const primitives = [42, 'foo', false]; + for (const value of primitives) { + assert.notThrows(() => getOwnPropertySymbols(value), `accept ${ typeof value }`); + } }); if (JSON) { diff --git a/tests/tests/es.symbol.js b/tests/tests/es.symbol.js index ff57a0e3f6c8..fc84006130b4 100644 --- a/tests/tests/es.symbol.js +++ b/tests/tests/es.symbol.js @@ -103,6 +103,10 @@ QUnit.test('Object.getOwnPropertySymbols', assert => { assert.deepEqual(getOwnPropertyNames(object).sort(), ['a', 'd', 's']); assert.strictEqual(getOwnPropertySymbols(object).length, 1); assert.strictEqual(getOwnPropertySymbols(Object.prototype).length, 0); + const primitives = [42, 'foo', false]; + for (const value of primitives) { + assert.notThrows(() => getOwnPropertySymbols(value), `accept ${ typeof value }`); + } }); if (JSON) {