diff options
author | 2023-08-18 19:58:03 -0700 | |
---|---|---|
committer | 2023-08-18 19:58:03 -0700 | |
commit | 943a6642243cbc8a180ab7108279dd7110ab1eaf (patch) | |
tree | 3382acb2c41536e942b8bf09f5f9fd4c97e551f8 /src/bun.js/scripts/generate-classes.ts | |
parent | d0664f83773fc39b8bd6b9ecdfc52833c7ce6b81 (diff) | |
download | bun-943a6642243cbc8a180ab7108279dd7110ab1eaf.tar.gz bun-943a6642243cbc8a180ab7108279dd7110ab1eaf.tar.zst bun-943a6642243cbc8a180ab7108279dd7110ab1eaf.zip |
Remove most C API usages, add debugger pretty printers for `Headers`, `URLSearchParams`, `FormData`, `Worker`, `EventTarget` (#4187)
* Add pretty printers for `Headers`, `URLSearchParams`, and `FormData`
* [untested] Add way to code generate getInternalProperties
* bump
* Bump Webkit
* Ref the event loop while loaded
* wip
* checkpoint
* another checkpoint
* The code has been written
* Fixup exports
* Fix all the errors
* Fix bug
* [console.log] Fix bug when printing non-reified types missing values
* Fix loading hash table
* fix plugin
* Fix ref & unref
* auto-unref
* various fixes
* Update bun.zig
* Set toStringTag
* Delete code for macro JSX
* Delete code for `bun dev` HTTP JS
* Move Bun.serve to C++ API
* Delete JSC C API code
* :scissors: :skull: code
* Use JSC C++ for `confirm`, `Crypto`, `prompt`, `alert`
* more dead code
* Update exports.zig
* Use JSC C++ API for FFI
* Remove remaining usages
* Remove remaining usages
* Update ffi.ts
* Update InternalModuleRegistryConstants.h
* draw the rest of the owl
* Update webcore.zig
* bind it
* Fix performance regression in crypto.randomUIUD()
* Update js_parser.zig
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/scripts/generate-classes.ts')
-rw-r--r-- | src/bun.js/scripts/generate-classes.ts | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/bun.js/scripts/generate-classes.ts b/src/bun.js/scripts/generate-classes.ts index ec0021637..0b88a3eb1 100644 --- a/src/bun.js/scripts/generate-classes.ts +++ b/src/bun.js/scripts/generate-classes.ts @@ -739,7 +739,7 @@ JSC_DEFINE_CUSTOM_GETTER(js${typeName}Constructor, (JSGlobalObject * lexicalGlob auto* prototype = jsDynamicCast<${prototypeName(typeName)}*>(JSValue::decode(thisValue)); if (UNLIKELY(!prototype)) - return throwVMTypeError(lexicalGlobalObject, throwScope); + return throwVMTypeError(lexicalGlobalObject, throwScope, "Cannot get constructor for ${typeName}"_s); return JSValue::encode(globalObject->${className(typeName)}Constructor()); } @@ -832,7 +832,8 @@ JSC_DEFINE_CUSTOM_SETTER(${symbolName( if (UNLIKELY(!thisObject)) { auto throwScope = DECLARE_THROW_SCOPE(vm); - return throwVMTypeError(lexicalGlobalObject, throwScope); + throwVMTypeError(lexicalGlobalObject, throwScope, "Expected 'this' to be instanceof ${typeName}"_s); + return JSValue::encode({}); } JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); @@ -910,6 +911,11 @@ function generateClassHeader(typeName, obj: ClassDefinition) { } `; } + var suffix = ""; + + if (obj.getInternalProperties) { + suffix += `JSC::JSValue getInternalProperties(JSC::VM &vm, JSC::JSGlobalObject *globalObject, ${name}*);`; + } return ` class ${name} final : public JSC::JSDestructibleObject { @@ -992,11 +998,20 @@ function generateClassHeader(typeName, obj: ClassDefinition) { ${renderCachedFieldsHeader(typeName, klass, proto, values)} }; + ${suffix} `; } function generateClassImpl(typeName, obj: ClassDefinition) { - const { klass: fields, finalize, proto, construct, estimatedSize, hasPendingActivity = false } = obj; + const { + klass: fields, + finalize, + proto, + construct, + estimatedSize, + hasPendingActivity = false, + getInternalProperties = false, + } = obj; const name = className(typeName); const DEFINE_VISIT_CHILDREN_LIST = [...Object.entries(fields), ...Object.entries(proto)] @@ -1076,6 +1091,24 @@ DEFINE_VISIT_OUTPUT_CONSTRAINTS(${name}); `; } + if (getInternalProperties) { + output += ` + extern "C" EncodedJSValue ${symbolName( + typeName, + "getInternalProperties", + )}(void* ptr, JSC::JSGlobalObject *globalObject, EncodedJSValue thisValue); + + JSC::JSValue getInternalProperties(JSC::VM &, JSC::JSGlobalObject *globalObject, ${name}* castedThis) + { + return JSValue::decode(${symbolName( + typeName, + "getInternalProperties", + )}(castedThis->impl(), globalObject, JSValue::encode(castedThis))); + } + + `; + } + if (finalize) { output += ` ${name}::~${name}() @@ -1220,6 +1253,7 @@ function generateZig( values = [], hasPendingActivity = false, structuredClone = false, + getInternalProperties = false, } = {} as ClassDefinition, ) { const exports = new Map<string, string>(); @@ -1246,6 +1280,10 @@ function generateZig( Object.values(klass).map(a => appendSymbols(exports, name => classSymbolName(typeName, name), a)); Object.values(proto).map(a => appendSymbols(exports, name => protoSymbolName(typeName, name), a)); + if (getInternalProperties) { + exports.set("getInternalProperties", symbolName(typeName, "getInternalProperties")); + } + if (structuredClone) { exports.set("onStructuredCloneSerialize", symbolName(typeName, "onStructuredCloneSerialize")); @@ -1306,6 +1344,14 @@ function generateZig( } `; + if (getInternalProperties) { + output += ` + if (@TypeOf(${typeName}.getInternalProperties) != (fn(*${typeName}, globalThis: *JSC.JSGlobalObject, JSC.JSValue thisValue) callconv(.C) JSC.JSValue { + @compileLog("${typeName}.getInternalProperties is not a getInternalProperties function"); + } + `; + } + if (structuredClone === "transferable") { exports.set("structuredClone", symbolName(typeName, "onTransferableStructuredClone")); output += ` |