-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for remaining private methods #9306
base: main
Are you sure you want to change the base?
Conversation
00dc865
to
d8af2bd
Compare
❌🪟 @jdalton, there are 473 test regressions on Windows x86_64
|
ef36e7a
to
5e9f82f
Compare
if (typeof value === null) throw new Error("Invalid enum object " + name + " defined in " + import.meta.file); | ||
const keys = Array.isArray(value) ? value : Object.keys(value).filter(k => !k.match(/^[0-9]+$/)); | ||
define[`$${name}IdToLabel`] = "[" + keys.map(k => `"${k}"`).join(", ") + "]"; | ||
define[`$${name}LabelToId`] = "{" + keys.map(k => `"${k}": ${keys.indexOf(k)}`).join(", ") + "}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☝️ Used the index
param of map
instead of keys.indexOf
.
if (typeof value !== "object") throw new Error("Invalid enum object " + name + " defined in " + import.meta.file); | ||
if (typeof value === null) throw new Error("Invalid enum object " + name + " defined in " + import.meta.file); | ||
const keys = Array.isArray(value) ? value : Object.keys(value).filter(k => !k.match(/^[0-9]+$/)); | ||
define[`$${name}IdToLabel`] = "[" + keys.map(k => `"${k}"`).join(", ") + "]"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☝️ Simplified the join as the keys weren't in need of mapping.
}; | ||
|
||
// ------------------------------ // | ||
|
||
for (const name in enums) { | ||
const value = enums[name]; | ||
if (typeof value !== "object") throw new Error("Invalid enum object " + name + " defined in " + import.meta.file); | ||
if (typeof value === null) throw new Error("Invalid enum object " + name + " defined in " + import.meta.file); | ||
const keys = Array.isArray(value) ? value : Object.keys(value).filter(k => !k.match(/^[0-9]+$/)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k.match
produces an array or null. In this case we just needed a boolean so regexp.test
is a better fit.
global?: boolean; | ||
} | ||
|
||
/** Applies source code replacements as defined in `replacements` */ | ||
export function applyReplacements(src: string, length: number) { | ||
let slice = src.slice(0, length); | ||
let rest = src.slice(length); | ||
slice = slice.replace(/([^a-zA-Z0-9_\$])\$([a-zA-Z0-9_]+\b)/gm, `$1__intrinsic__$2`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☝️ a-zA-Z0-9_
is \w
. (there's case folding too but not an issue here)
src/codegen/replacements.ts
Outdated
} | ||
let match; | ||
if ((match = slice.match(/__intrinsic__(debug|assert)$/)) && rest.startsWith("(")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☝️ Doing the cheap check first (.startsWith
).
5e9f82f
to
7358e72
Compare
for (const replacement of replacements) { | ||
slice = slice.replace(replacement.from, replacement.to.replaceAll("$", "__intrinsic__").replaceAll("%", "$")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move replacement.to
transforms higher to ensure they are performed once and to improve consistency of transformation between replacements
and globalReplacements
.
f4d5219
to
f18a4ec
Compare
{ | ||
from: /\bnotImplementedIssueFn\(\s*([0-9]+)\s*,\s*((?:"[^"]*"|'[^']+'))\s*\)/g, | ||
to: "() => $throwTypeError(`${$2} is not implemented yet. See https://github.com/oven-sh/bun/issues/$1`)", | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this PR the globalReplacements
.to
was being transformed with.replaceAll("$", "__intrinsic__")
which would have made the $2
and $1
incorrectly transformed because it didn't have the transform that the replacements
.to
has for %1
, %2
, etc.
export const globalReplacements: ReplacementRule[] = [ | ||
{ | ||
from: /\bnotImplementedIssue\(\s*([0-9]+)\s*,\s*((?:"[^"]*"|'[^']+'))\s*\)/g, | ||
to: "new TypeError(`${$2} is not implemented yet. See https://github.com/oven-sh/bun/issues/$1`)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
notImplementedIssue
isn't used in our code ✂️ , where as notImplementedIssueFn
is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes in replacements.ts is great so far. i am happy to see someone else finally add something to the builtins bundler.
f18a4ec
to
a5ccb5c
Compare
8971d01
to
30b8332
Compare
30b8332
to
68ae23b
Compare
637b3d1
to
7e912a2
Compare
@@ -84,7 +84,7 @@ void JSNextTickQueue::drain(JSC::VM& vm, JSC::JSGlobalObject* globalObject) | |||
|
|||
if (!isEmpty()) { | |||
if (mustResetContext) { | |||
globalObject->m_asyncContextData.get()->putInternalField(vm, 0, jsUndefined()); | |||
globalObject->asyncContextTuple()->putInternalField(vm, 0, jsUndefined()); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this PR I've made a distinction between the asyncContextTuple and asyncContextData because in main the current forms are conflated as asyncContext
which gets confusing (is it the tuple or the data of the tuple). With this we have a clear and consistent distinction.
@@ -864,8 +865,8 @@ export function onPullDirectStream(controller) { | |||
deferFlush = controller._deferFlush; | |||
controller._deferFlush = controller._deferClose = 0; | |||
|
|||
if (asyncContext) { | |||
$putInternalField($asyncContext, 0, prev); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed as prev
was not defined in the outer scope.
7e912a2
to
dcfdfcb
Compare
2e79afa
to
515bd66
Compare
515bd66
to
8843060
Compare
What does this PR do?
Add support for remaining private methods.
This is a follow-up to oven-sh/WebKit#46.