Skip to content

Commit

Permalink
Fix shim test fails
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Oct 2, 2024
1 parent a89ab4f commit 0ee61e4
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/npm/date/Date.parse/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { defineProperty: ObjectDefineProperty } = Object

module.exports = function shimDateParse() {
const polyfill = getPolyfill()
if (polyfill && Date.parse !== polyfill) {
if (Date.parse !== polyfill) {
ObjectDefineProperty(Date, 'parse', {
__proto__: null,
configurable: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const impl = require('./implementation')
const getPolyfill = require('./polyfill')
const polyfill = getPolyfill()

const desc = value => ({
__proto__: null,
Expand All @@ -11,11 +12,11 @@ const desc = value => ({

module.exports = Object.defineProperties(
function drop(thisArg, limit = 0) {
return new.target ? impl() : Reflect.apply(impl, thisArg, [limit])
return new.target ? polyfill() : Reflect.apply(polyfill, thisArg, [limit])
},
{
getPolyfill: desc(require('./polyfill')),
implementation: desc(impl),
getPolyfill: desc(getPolyfill),
implementation: desc(require('./implementation')),
shim: desc(require('./shim'))
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const impl = require('./implementation')
const getPolyfill = require('./polyfill')
const polyfill = getPolyfill()

const desc = value => ({
__proto__: null,
Expand All @@ -11,11 +12,13 @@ const desc = value => ({

module.exports = Object.defineProperties(
function filter(thisArg, predicate) {
return new.target ? new impl() : Reflect.apply(impl, thisArg, [predicate])
return new.target
? new polyfill()
: Reflect.apply(polyfill, thisArg, [predicate])
},
{
getPolyfill: desc(require('./polyfill')),
implementation: desc(impl),
getPolyfill: desc(getPolyfill),
implementation: desc(require('./implementation')),
shim: desc(require('./shim'))
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const impl = require('./implementation')
const getPolyfill = require('./polyfill')
const polyfill = getPolyfill()

const desc = value => ({
__proto__: null,
Expand All @@ -11,11 +12,13 @@ const desc = value => ({

module.exports = Object.defineProperties(
function flatMap(thisArg, mapper) {
return new.target ? new impl() : Reflect.apply(impl, thisArg, [mapper])
return new.target
? new polyfill()
: Reflect.apply(polyfill, thisArg, [mapper])
},
{
getPolyfill: desc(require('./polyfill')),
implementation: desc(impl),
getPolyfill: desc(getPolyfill),
implementation: desc(require('./implementation')),
shim: desc(require('./shim'))
}
)
Expand Down
11 changes: 7 additions & 4 deletions packages/npm/es-iterator-helpers/Iterator.prototype.map/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const impl = require('./implementation')
const getPolyfill = require('./polyfill')
const polyfill = getPolyfill()

const desc = value => ({
__proto__: null,
Expand All @@ -11,11 +12,13 @@ const desc = value => ({

module.exports = Object.defineProperties(
function map(thisArg, mapper) {
return new.target ? new impl() : Reflect.apply(impl, thisArg, [mapper])
return new.target
? new polyfill()
: Reflect.apply(polyfill, thisArg, [mapper])
},
{
getPolyfill: desc(require('./polyfill')),
implementation: desc(impl),
getPolyfill: desc(getPolyfill),
implementation: desc(require('./implementation')),
shim: desc(require('./shim'))
}
)
Expand Down
4 changes: 3 additions & 1 deletion packages/npm/regexp.prototype.flags/auto.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/* empty */
'use strict'

require('./shim')()
40 changes: 39 additions & 1 deletion packages/npm/regexp.prototype.flags/implementation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
'use strict'

module.exports = RegExp.prototype.__lookupGetter__('flags')
const { flagsGetter } = require('./shared')

module.exports = {
get flags() {
if (new.target || this === null || typeof this !== 'object') {
// Defer to builtin flags getter for the error case.
return flagsGetter.call(this)
}
// Flag check order defined as hasIndices, global, ignoreCase, multiline,
// dotAll, unicode, unicodeSets, and sticky.
// https://tc39.es/ecma262/#sec-get-regexp.prototype.flags
let result = ''
if (this.hasIndices) {
result += 'd'
}
if (this.global) {
result += 'g'
}
if (this.ignoreCase) {
result += 'i'
}
if (this.multiline) {
result += 'm'
}
if (this.dotAll) {
result += 's'
}
if (this.unicode) {
result += 'u'
}
if (this.unicodeSets) {
result += 'v'
}
if (this.sticky) {
result += 'y'
}
return result
}
}.__lookupGetter__('flags')
9 changes: 5 additions & 4 deletions packages/npm/regexp.prototype.flags/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const impl = require('./implementation')
const getPolyfill = require('./polyfill')
const polyfill = getPolyfill()

const desc = value => ({
__proto__: null,
Expand All @@ -11,11 +12,11 @@ const desc = value => ({

module.exports = Object.defineProperties(
function flags(thisArg) {
return new.target ? new impl() : Reflect.apply(impl, thisArg, [])
return new.target ? new polyfill() : Reflect.apply(polyfill, thisArg, [])
},
{
getPolyfill: desc(require('./polyfill')),
implementation: desc(impl),
getPolyfill: desc(getPolyfill),
implementation: desc(require('./implementation')),
shim: desc(require('./shim'))
}
)
Expand Down
14 changes: 13 additions & 1 deletion packages/npm/regexp.prototype.flags/polyfill.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
'use strict'

const impl = require('./implementation')
const { flagsGetter } = require('./shared')

module.exports = function getPolyfill() {
return impl
let calls = ''
flagsGetter.call({
// eslint-disable-next-line getter-return
get hasIndices() {
calls += 'd'
},
// eslint-disable-next-line getter-return
get sticky() {
calls += 'y'
}
})
return calls === 'dy' ? flagsGetter : impl
}
5 changes: 5 additions & 0 deletions packages/npm/regexp.prototype.flags/shared.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare interface InternalShared {
flagsGetter(): string
}
declare const shared: InternalShared
export = shared
7 changes: 7 additions & 0 deletions packages/npm/regexp.prototype.flags/shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict'

const flagsGetter = RegExp.prototype.__lookupGetter__('flags')

module.exports = {
flagsGetter
}
17 changes: 15 additions & 2 deletions packages/npm/regexp.prototype.flags/shim.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
'use strict'

const impl = require('./implementation')
const getPolyfill = require('./polyfill')

const { defineProperty: ObjectDefineProperty } = Object
const { __lookupGetter__: ObjectProtoLookupGetter } = Object.prototype
const { prototype: RegExpPrototype } = RegExp

module.exports = function shimRegExpProtoFlags() {
return impl
const polyfill = getPolyfill()
if (ObjectProtoLookupGetter.call(RegExpPrototype, 'flags') !== polyfill) {
ObjectDefineProperty(RegExpPrototype, 'flags', {
__proto__: null,
configurable: true,
enumerable: false,
get: polyfill
})
}
return polyfill
}

0 comments on commit 0ee61e4

Please sign in to comment.