aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/scripts/generate-classes.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/scripts/generate-classes.ts')
-rw-r--r--src/bun.js/scripts/generate-classes.ts52
1 files changed, 13 insertions, 39 deletions
diff --git a/src/bun.js/scripts/generate-classes.ts b/src/bun.js/scripts/generate-classes.ts
index b6fbe0915..ae28f4fe5 100644
--- a/src/bun.js/scripts/generate-classes.ts
+++ b/src/bun.js/scripts/generate-classes.ts
@@ -335,7 +335,7 @@ function generatePrototype(typeName, obj) {
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);`;
+ )}Callback, ImplementationVisibility::Public), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | 0);`;
}
return `
@@ -420,6 +420,7 @@ function generatePrototypeHeader(typename) {
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
+ STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(${proto}, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
@@ -555,7 +556,7 @@ JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES ${name}::construct(JSC::JSGlobalObj
${className(typeName)}* instance = ${className(typeName)}::create(vm, globalObject, structure, ptr);
${
obj.estimatedSize
- ? `vm.heap.reportExtraMemoryAllocated(${symbolName(obj.name, "estimatedSize")}(instance->wrapped()));`
+ ? `vm.heap.reportExtraMemoryAllocated(instance, ${symbolName(obj.name, "estimatedSize")}(instance->wrapped()));`
: ""
}
@@ -1208,7 +1209,11 @@ extern "C" EncodedJSValue ${typeName}__create(Zig::GlobalObject* globalObject, v
auto &vm = globalObject->vm();
JSC::Structure* structure = globalObject->${className(typeName)}Structure();
${className(typeName)}* instance = ${className(typeName)}::create(vm, globalObject, structure, ptr);
- ${obj.estimatedSize ? `vm.heap.reportExtraMemoryAllocated(${symbolName(obj.name, "estimatedSize")}(ptr));` : ""}
+ ${
+ obj.estimatedSize
+ ? `vm.heap.reportExtraMemoryAllocated(instance, ${symbolName(obj.name, "estimatedSize")}(ptr));`
+ : ""
+ }
return JSValue::encode(instance);
}
@@ -1556,43 +1561,19 @@ ${[...exports]
function generateLazyClassStructureHeader(typeName, { klass = {}, proto = {} }) {
return `
- JSC::Structure* ${className(typeName)}Structure() { return m_${className(
+ JSC::Structure* ${className(typeName)}Structure() { return m_${className(
typeName,
)}.getInitializedOnMainThread(this); }
- JSC::JSObject* ${className(typeName)}Constructor() { return m_${className(
+ JSC::JSObject* ${className(typeName)}Constructor() { return m_${className(
typeName,
)}.constructorInitializedOnMainThread(this); }
- JSC::JSValue ${className(typeName)}Prototype() { return m_${className(
+ JSC::JSValue ${className(typeName)}Prototype() { return m_${className(
typeName,
)}.prototypeInitializedOnMainThread(this); }
JSC::LazyClassStructure m_${className(typeName)};
- bool has${className(typeName)}SetterValue { false };
- mutable JSC::WriteBarrier<JSC::Unknown> m_${className(typeName)}SetterValue;
- `.trim();
-}
-
-function generateLazyStructureHeader(typeName, { klass = {}, proto = {} }) {
- return `
- JSC::Structure* ${className(typeName)}Structure() { return m_${className(typeName)}.get(this); }
- JSC::LazyProperty<Zig::GlobalObject, Structure> m_${className(typeName)};
- bool has${className(typeName)}SetterValue { false };
- mutable JSC::WriteBarrier<JSC::Unknown> m_${className(typeName)}SetterValue;
`.trim();
}
-function generateLazyStructureImpl(typeName, { klass = {}, proto = {} }) {
- return `
- m_${className(typeName)}.initLater(
- [](const JSC::LazyProperty<JSC::JSGlobalObject, JSC::JSObject>::Initializer& init) {
- auto *prototype = WebCore::${className(
- typeName,
- )}::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.owner));
- init.set(WebCore::${className(typeName)}::createStructure(init.vm, init.owner, prototype));
- });
-
- `.trim();
-}
-
function generateLazyClassStructureImpl(typeName, { klass = {}, proto = {}, noConstructor = false }) {
return `
m_${className(typeName)}.initLater(
@@ -1685,7 +1666,7 @@ const GENERATED_CLASSES_IMPL_FOOTER = `
function initLazyClasses(initLaterFunctions) {
return `
-void GlobalObject::initGeneratedLazyClasses() {
+ALWAYS_INLINE void GlobalObject::initGeneratedLazyClasses() {
${initLaterFunctions.map(a => a.trim()).join("\n ")}
}
@@ -1698,14 +1679,7 @@ function visitLazyClasses(classes) {
template<typename Visitor>
void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor& visitor)
{
- ${classes
- .map(
- a =>
- `thisObject->m_${className(a.name)}.visit(visitor); visitor.append(thisObject->m_${className(
- a.name,
- )}SetterValue);`,
- )
- .join("\n ")}
+ ${classes.map(a => `thisObject->m_${className(a.name)}.visit(visitor);`).join("\n ")}
}
`.trim();