Skip to content

Commit

Permalink
Merge pull request #539 from turbobridge/getownpropsymbols_fix
Browse files Browse the repository at this point in the history
Fix broken getOwnPropertySymbols in Mobile Chrome 38 and 39
  • Loading branch information
zloirock authored May 10, 2019
2 parents fe7c851 + 0dc60df commit a57ad74
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/core-js/modules/es.symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 () {
Expand Down
1 change: 1 addition & 0 deletions tests/compat/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down
4 changes: 4 additions & 0 deletions tests/pure/es.symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions tests/tests/es.symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a57ad74

Please sign in to comment.