diff options
author | 2023-02-22 19:04:54 -0800 | |
---|---|---|
committer | 2023-02-22 19:04:54 -0800 | |
commit | 0911bd3af2aceca487f3159f20c0400fb45bdc92 (patch) | |
tree | 8ad4317d12f5ba3ba878272dbf03cc23c68dddf0 /src/bun.js/scripts/generate-classes.ts | |
parent | 9f53a2210cac920c34c858d1fb408dbf9b8d8f94 (diff) | |
download | bun-0911bd3af2aceca487f3159f20c0400fb45bdc92.tar.gz bun-0911bd3af2aceca487f3159f20c0400fb45bdc92.tar.zst bun-0911bd3af2aceca487f3159f20c0400fb45bdc92.zip |
Support well known symobls in prototypes for generated classes
Diffstat (limited to 'src/bun.js/scripts/generate-classes.ts')
-rw-r--r-- | src/bun.js/scripts/generate-classes.ts | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/bun.js/scripts/generate-classes.ts b/src/bun.js/scripts/generate-classes.ts index 11b5e3a15..d39ea027b 100644 --- a/src/bun.js/scripts/generate-classes.ts +++ b/src/bun.js/scripts/generate-classes.ts @@ -12,15 +12,15 @@ const directoriesToSearch = [ ]; function symbolName(typeName, name) { - return `${typeName}__${name}`; + return `${typeName}__${name.replaceAll("@@", "")}`; } function protoSymbolName(typeName, name) { - return `${typeName}Prototype__${name}`; + return `${typeName}Prototype__${name.replaceAll("@@", "")}`; } function classSymbolName(typeName, name) { - return `${typeName}Class__${name}`; + return `${typeName}Class__${name.replaceAll("@@", "")}`; } function subspaceFor(typeName) { @@ -266,6 +266,7 @@ export function generateHashTable(nameToUse, symbolName, typeName, obj, props = for (const name in props) { if ("internal" in props[name]) continue; + if (name.startsWith("@@")) continue; rows.push(propRow(symbolName, typeName, name, props[name], wrapped, defaultPropertyAttributes)); } @@ -300,6 +301,22 @@ ${rows.join(" ,\n")} function generatePrototype(typeName, obj) { const proto = prototypeName(typeName); const { proto: protoFields } = obj; + var specialSymbols = ""; + + for (const name in protoFields) { + if (!name.startsWith("@@")) { + continue; + } + + const symbol = name.slice(2); + + specialSymbols += ` + this->putDirect(vm, vm.propertyNames->${symbol}Symbol, JSFunction::create(vm, globalObject, 1, String("${symbol}"_s), ${protoSymbolName( + typeName, + symbol, + )}Callback, ImplementationVisibility::Public), PropertyAttribute::Function | PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | 0);`; + } + return ` ${ obj.construct @@ -331,7 +348,7 @@ ${renderFieldsImpl(protoSymbolName, typeName, obj, protoFields, obj.values || [] void ${proto}::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); - reifyStaticProperties(vm, ${className(typeName)}::info(), ${proto}TableValues, *this); + reifyStaticProperties(vm, ${className(typeName)}::info(), ${proto}TableValues, *this);${specialSymbols} JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); } |