Skip to content
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 remaining private methods #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jdalton
Copy link

@jdalton jdalton commented Mar 7, 2024

Add remaining private methods.
Related to oven-sh/bun#9306 and oven-sh/bun#9076

Example

console.log("Array");
console.log("Array.from", Array.$from);
console.log("Array.from2", Array.$from === Array.from);
console.log("Array.isArray", Array.$isArray);
console.log("Array.isArray2", Array.$isArray === Array.isArray);
console.log("Array.of", Array.$of);
console.log("Array.of2", Array.$of === Array.of);
console.log("Array.@@species", Array.$$species);
console.log("constructor", Array.prototype.$constructor);
console.log("constructor2", Array.prototype.$constructor === Array);
console.log("constructor3", Array.prototype.$constructor === $Array);
console.log("length", Array.prototype.$length);
console.log("['a', 'b', 'c'].@length", ["a", "b", "c"].$length);
console.log("concat", Array.prototype.$concat);
console.log("copyWithin", Array.prototype.$copyWithin);
console.log("fill", Array.prototype.$fill);
console.log("find", Array.prototype.$find);
console.log("findIndex", Array.prototype.$findIndex);
console.log("lastIndexOf", Array.prototype.$lastIndexOf);
console.log("pop", Array.prototype.$pop);
console.log("push", Array.prototype.$push);
console.log("reverse", Array.prototype.$reverse);
console.log("shift", Array.prototype.$shift);
console.log("shift2", Array.prototype.$shift === Array.prototype.shift);
console.log("unshift", Array.prototype.$unshift);
console.log("slice", Array.prototype.$slice);
console.log("sort", Array.prototype.$sort);
console.log("splice", Array.prototype.$splice);
console.log("includes", Array.prototype.$includes);
console.log("indexOf", Array.prototype.$indexOf);
console.log("join", Array.prototype.$join);
console.log("keys", Array.prototype.$keys);
console.log("entries", Array.prototype.$entries);
console.log("values", Array.prototype.$values);
console.log("forEach", Array.prototype.$forEach);
console.log("filter", Array.prototype.$filter);
console.log("flat", Array.prototype.$flat);
console.log("flatMap", Array.prototype.$flatMap);
console.log("map", Array.prototype.$map);
console.log("every", Array.prototype.$every);
console.log("some", Array.prototype.$some);
console.log("reduce", Array.prototype.$reduce);
console.log("reduceRight", Array.prototype.$reduceRight);
console.log("toLocaleString", Array.prototype.$toLocaleString);
console.log("toString", Array.prototype.$toString);
console.log("at", Array.prototype.$at);
console.log("findLast", Array.prototype.$findLast);
console.log("findLastIndex", Array.prototype.$findLastIndex);
console.log(String(Symbol.iterator), Array.prototype.$$iterator);
console.log(String(Symbol.unscopables), Array.prototype.$$unscopables);

var a = [1, 2, 3];
Symbol.iterator;
a[$$iterator] = "foo";
console.log(Symbol.iterator);
console.log(a.$$iterator);
console.log(a[$$iterator]);

console.log("String");
console.log("constructor", String.prototype.$constructor);
console.log("constructor2", String.prototype.$constructor === String);
console.log("constructor3", String.prototype.$constructor === $String);
console.log("length", String.prototype.$length);
console.log("'abc'.@length", "abc".$length);
console.log("at", String.prototype.$at);
console.log("charAt", String.prototype.$charAt);
console.log("charCodeAt", String.prototype.$charCodeAt);
console.log("charCodeAt2", String.prototype.$charCodeAt === String.prototype.charCodeAt);
console.log("codePointAt", String.prototype.$codePointAt);
console.log("concat", String.prototype.$concat);
console.log("endsWith", String.prototype.$endsWith);
console.log("includes", String.prototype.$includes);
console.log("indexOf", String.prototype.$indexOf);
console.log("isWellFormed", String.prototype.$isWellFormed);
console.log("lastIndexOf", String.prototype.$lastIndexOf);
console.log("match", String.prototype.$match);
console.log("matchAll", String.prototype.$matchAll);
console.log("normalize", String.prototype.$normalize);
console.log("padEnd", String.prototype.$padEnd);
console.log("padStart", String.prototype.$padStart);
console.log("repeat", String.prototype.$repeat);
console.log("replace", String.prototype.$replace);
console.log("replaceAll", String.prototype.$replaceAll);
console.log("search", String.prototype.$search);
console.log("slice", String.prototype.$slice);
console.log("split", String.prototype.$split);
console.log("startsWith", String.prototype.$startsWith);
console.log("substr", String.prototype.$substr);
console.log("substring", String.prototype.$substring);
console.log("localeCompare", String.prototype.$localeCompare);
console.log("toLocaleLowerCase", String.prototype.$toLocaleLowerCase);
console.log("toLocaleUpperCase", String.prototype.$toLocaleUpperCase);
console.log("toLowerCase", String.prototype.$toLowerCase);
console.log("toUpperCase", String.prototype.$toUpperCase);
console.log("trim", String.prototype.$trim);
console.log("trimLeft", String.prototype.$trimLeft);
console.log("trimStart", String.prototype.$trimStart);
console.log("trimEnd", String.prototype.$trimEnd);
console.log("trimRight", String.prototype.$trimRight);
console.log("toWellFormed", String.prototype.$toWellFormed);
console.log("toString", String.prototype.$toString);
console.log("valueOf", String.prototype.$valueOf);
console.log(String(Symbol.iterator), String.prototype.$$iterator);

Output

Array
Array.from [Function: from]
Array.from2 true
Array.isArray [Function: isArray]
Array.isArray2 true
Array.of [Function: of]
Array.of2 true
Array.@@species [class Array]
constructor [class Array]
constructor2 true
constructor3 true
length 0
['a', 'b', 'c'].@length 3
concat [Function: concat]
copyWithin [Function: copyWithin]
fill [Function: fill]
find [Function: find]
findIndex [Function: findIndex]
lastIndexOf [Function: lastIndexOf]
pop [Function: pop]
push [Function: push]
reverse [Function: reverse]
shift [Function: anonymous]
shift2 false
unshift [Function: unshift]
slice [Function: slice]
sort [Function: sort]
splice [Function: splice]
includes [Function: includes]
indexOf [Function: indexOf]
join [Function: join]
keys [Function: keys]
entries [Function: entries]
values [Function: values]
forEach [Function: forEach]
filter [Function: filter]
flat [Function: flat]
flatMap [Function: flatMap]
map [Function: map]
every [Function: every]
some [Function: some]
reduce [Function: reduce]
reduceRight [Function: reduceRight]
toLocaleString [Function: toLocaleString]
toString [Function: toString]
at [Function: at]
findLast [Function: findLast]
findLastIndex [Function: findLastIndex]
Symbol(Symbol.iterator) [Function: values]
Symbol(Symbol.unscopables) {
  at: true,
  copyWithin: true,
  entries: true,
  fill: true,
  find: true,
  findIndex: true,
  findLast: true,
  findLastIndex: true,
  flat: true,
  flatMap: true,
  includes: true,
  keys: true,
  toReversed: true,
  toSorted: true,
  toSpliced: true,
  values: true,
}
Symbol(Symbol.iterator)
[Function: values]
foo
String
constructor [class String]
constructor2 true
constructor3 true
length 0
'abc'.@length 3
at [Function: at]
charAt [Function: charAt]
charCodeAt [Function: charCodeAt]
charCodeAt2 true
codePointAt [Function: codePointAt]
concat [Function: concat]
endsWith [Function: anonymous]
includes [Function: includes]
indexOf [Function: indexOf]
isWellFormed [Function: isWellFormed]
lastIndexOf [Function: lastIndexOf]
match [Function: match]
matchAll [Function: matchAll]
normalize [Function: normalize]
padEnd [Function: padEnd]
Add remaining private Array and String methods
padStart [Function: padStart]
repeat [Function: repeat]
replace [Function: replace]
replaceAll [Function: replaceAll]
search [Function: search]
slice [Function: slice]
split [Function: split]
startsWith [Function: startsWith]
substr [Function: anonymous]
substring [Function: substring]
localeCompare [Function: localeCompare]
toLocaleLowerCase [Function: toLocaleLowerCase]
toLocaleUpperCase [Function: toLocaleUpperCase]
toLowerCase [Function: toLowerCase]
toUpperCase [Function: toUpperCase]
trim [Function: trim]
trimLeft [Function: trimStart]
trimStart [Function: trimStart]
trimEnd [Function: trimEnd]
trimRight [Function: trimEnd]
toWellFormed [Function: toWellFormed]
toString [Function: valueOf]
valueOf [Function: valueOf]
Symbol(Symbol.iterator) [Function: [Symbol.iterator]]

macro($unscopables)
#else
#define BUN_JSC_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(macro)
#endif
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditionally add private names if USE(BUN_JSC_ADDITIONS).

@jdalton jdalton force-pushed the jdalton/array-private-methods branch 2 times, most recently from 577ceea to 842bdf0 Compare March 12, 2024 16:50
@jdalton jdalton changed the title Add remaining private Array methods Add remaining private Array and String methods Mar 12, 2024
@jdalton jdalton force-pushed the jdalton/array-private-methods branch from 842bdf0 to b8b7097 Compare March 22, 2024 17:42
@jdalton jdalton changed the title Add remaining private Array and String methods Add remaining private methods Mar 22, 2024
@jdalton jdalton force-pushed the jdalton/array-private-methods branch 9 times, most recently from 1f396a2 to a22b5f4 Compare March 29, 2024 03:34
@@ -210,7 +211,7 @@ namespace JSC {
macro(hasOwn) \
macro(indexOf) \
macro(pop) \
macro(asyncContext) \

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ extra newline aligns with WebKit repo source (so closer to original source material).

#if USE(BUN_JSC_ADDITIONS)
ExpressionNode* expr = n->isArgumentList() ? static_cast<ArgumentListNode*>(n)->m_expr : nullptr;
if (expr && expr->isLinkTimeConstant()) return moveLinkTimeConstant(newTemporary(), static_cast<BytecodeIntrinsicNode*>(expr)->linkTimeConstant());
#endif
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ With this tweak in emitNode we now can pass byteCodeIntrinsics and linkTimeConstants as arguments 😮

@@ -33,6 +33,7 @@ class CodeBlock;
class JSGlobalObject;

#define JSC_FOREACH_LINK_TIME_CONSTANTS(v) \
BUN_JSC_LINK_TIME_CONSTANTS(v) \
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ This lil' macro lives in CommonIdentifiers.h and co-locates all of our BUN_JSC_ADDITIONS names

my $key = $1;
my $val = $2;
my $att = $3;
my $param = $4;
my $intrinsic = $5;
my $if = $6;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now support conditionally reifying of props (with something like #if(USE(BUN_JSC_ADDITIONS))) as seen here. Example:

/* Source for JSGlobalObject.lut.h
@begin globalObjectTable
  isNaN              globalFuncIsNaN         DontEnum|Function 1       GlobalIsNaNIntrinsic
  isFinite           JSBuiltin               DontEnum|Function 1
  escape             globalFuncEscape        DontEnum|Function 1
  SuppressedError    JSGlobalObject::m_foo   DontEnum|ClassStructure   #if(USE(BUN_JSC_ADDITIONS))
  Proxy              createProxyProperty     DontEnum|PropertyCallback
@end
*/

#if USE(BUN_JSC_ADDITIONS)
if (ident.isPrivateName() || ident.isWellKnownSymbol(vm))
return identifierToJSValue(vm, ident);
#endif
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ Allows passing @@iterator and other symbols to methods like foo.@__lookupGetter(@@iterator).

#define FOR_EACH_JSC_COMMON_ISO_SUBSPACE(v) \
BUN_JSC_COMMON_ISO_SUBSPACES(v) \
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ Small injection point for Bun addition names

#if USE(BUN_JSC_ADDITIONS)
if (ident.isPrivateName() || ident.isWellKnownSymbol(vm))
return identifierToJSValue(vm, ident);
#endif
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if USE(BUN_JSC_ADDITIONS)
if (ident.isPrivateName() || ident.isWellKnownSymbol(vm))
return identifierToJSValue(vm, ident);
#endif
Copy link
Author

@jdalton jdalton Mar 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if USE(BUN_JSC_ADDITIONS)
virtual bool isArgumentList() const { return false; }
virtual bool isLinkTimeConstant() const { return false; }
#endif
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ Make working with these Nodes easier (less casting between types).

@@ -950,6 +954,9 @@ namespace JSC {

ArgumentListNode* m_next { nullptr };
ExpressionNode* m_expr;
#if USE(BUN_JSC_ADDITIONS)
bool isArgumentList() const final { return true; }
#endif
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ Allows us to detect the node in emitNode

macro(subarray) \
/* WeakRef */ \
macro(deref) \

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ All the names together, shared, and organized 💆

vm.propertyNames->builtinNames().lookUpWellKnownSymbol(uid->substring(strlen("Symbol."))) != nullptr
);
}
#endif
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fields->putInternalField(vm, 0, a);
fields->putInternalField(vm, 1, b);
fields->finishCreation(vm);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit. Reuse in a way to longer adding fields After finishCreation.


globalObject->queueMicrotask(job, argument0, argument1, argument2, argument3, argument4);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support passing a 4th extra argument to queueMicrotask to avoid jamming everything into the 3rd (required duck typing and extra checks to manage).

@@ -28,7 +28,6 @@
#include "ArrayAllocationProfile.h"
#include "ArrayConstructor.h"
#include "ArrayPrototype.h"
#include "ErrorType.h"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the inclusion makes sense the original WebKit source omits this so I am too (closer to original source).

@jdalton jdalton force-pushed the jdalton/array-private-methods branch from a22b5f4 to 87c3d24 Compare March 29, 2024 15:19
@jdalton jdalton force-pushed the jdalton/array-private-methods branch from 87c3d24 to 8dcfec5 Compare March 30, 2024 12:46
@jdalton
Copy link
Author

jdalton commented Apr 8, 2024

Superseded by the jdalton/webkit-bun-patch branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant