feat(codemode): expand standard library parity (#37943)
This commit is contained in:
parent
c7aa47c144
commit
3da0dea8e7
11 changed files with 171 additions and 15 deletions
|
|
@ -2,11 +2,16 @@
|
|||
* Portions adapted from Test262 at revision 250f204f23a9249ff204be2baec29600faae7b75:
|
||||
* - test/built-ins/Date/value-to-primitive-result-non-string-prim.js
|
||||
* - test/built-ins/Date/value-to-primitive-result-string.js
|
||||
* - test/built-ins/Date/prototype/toUTCString/format.js
|
||||
* - test/built-ins/Date/prototype/toUTCString/invalid-date.js
|
||||
* - test/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T8.js
|
||||
*
|
||||
* CodeMode does not support Symbol.toPrimitive, so these cases exercise the same Date-constructor primitive-result
|
||||
* CodeMode does not support Symbol.toPrimitive, so the Date-constructor cases exercise the same primitive-result
|
||||
* handling through supported own valueOf and toString functions.
|
||||
*
|
||||
* Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
* Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
* Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
* Test262 portions are governed by the BSD license in LICENSE.test262.
|
||||
*/
|
||||
import { describe, expect, test } from "bun:test"
|
||||
|
|
@ -175,6 +180,25 @@ describe("Date", () => {
|
|||
expect(await value(`return typeof new Date(0)`)).toBe("object")
|
||||
expect(await value(`return new Date(0).nope === undefined`)).toBe(true)
|
||||
})
|
||||
|
||||
test("toUTCString and toGMTString use the native UTC format", async () => {
|
||||
expect(
|
||||
await value(`
|
||||
const date = new Date(0)
|
||||
return [
|
||||
date.toUTCString(),
|
||||
date.toGMTString(),
|
||||
new Date(NaN).toUTCString(),
|
||||
new Date("0020-01-01T00:00:00Z").toUTCString(),
|
||||
]
|
||||
`),
|
||||
).toEqual([
|
||||
"Thu, 01 Jan 1970 00:00:00 GMT",
|
||||
"Thu, 01 Jan 1970 00:00:00 GMT",
|
||||
"Invalid Date",
|
||||
"Wed, 01 Jan 0020 00:00:00 GMT",
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("RegExp", () => {
|
||||
|
|
@ -211,6 +235,51 @@ describe("RegExp", () => {
|
|||
).toEqual(["1", "22"])
|
||||
})
|
||||
|
||||
test("lastIndex is writable and exec coerces its stored value", async () => {
|
||||
expect(
|
||||
await value(`
|
||||
const pattern = /(?:ab|cd)\\d?/g
|
||||
pattern.lastIndex = "12"
|
||||
const stored = [pattern.lastIndex, typeof pattern.lastIndex]
|
||||
const match = pattern.exec("aacd2233ab12nm444ab42")
|
||||
pattern.lastIndex = 0
|
||||
return [stored, match[0], match.index, pattern.lastIndex, delete pattern.lastIndex]
|
||||
`),
|
||||
).toEqual([["12", "string"], "ab4", 17, 0, false])
|
||||
})
|
||||
|
||||
test("exec coerces CodeMode data objects assigned to lastIndex", async () => {
|
||||
expect(
|
||||
await value(`
|
||||
const pattern = /a/g
|
||||
pattern.lastIndex = {}
|
||||
const stored = pattern.lastIndex
|
||||
const match = pattern.exec("ba")
|
||||
pattern.lastIndex = 10
|
||||
const missed = pattern.exec("a")
|
||||
return [stored, match.index, pattern.lastIndex, missed]
|
||||
`),
|
||||
).toEqual([{}, 1, 0, null])
|
||||
})
|
||||
|
||||
test("non-global exec and test coerce and preserve lastIndex", async () => {
|
||||
expect(
|
||||
await value(`
|
||||
const execPattern = /a/
|
||||
const execIndex = {}
|
||||
execPattern.lastIndex = execIndex
|
||||
const match = execPattern.exec("ba")
|
||||
|
||||
const testPattern = /a/
|
||||
const testIndex = {}
|
||||
testPattern.lastIndex = testIndex
|
||||
const matched = testPattern.test("ba")
|
||||
|
||||
return [match.index, execPattern.lastIndex === execIndex, matched, testPattern.lastIndex === testIndex]
|
||||
`),
|
||||
).toEqual([1, true, true, true])
|
||||
})
|
||||
|
||||
test("an unmatched string pattern returns null", async () => {
|
||||
expect(await value(`return "abc".match(/\\d/)`)).toBeNull()
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue