diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/bindings/KeyObject.cpp | 19 | ||||
-rw-r--r-- | src/bun.js/bindings/Path.cpp | 44 | ||||
-rw-r--r-- | src/bun.js/webcore/streams.classes.ts | 5 | ||||
-rw-r--r-- | src/codegen/generate-classes.ts (renamed from src/bun.js/scripts/generate-classes.ts) | 61 | ||||
-rw-r--r-- | src/codegen/generate-jssink.ts (renamed from src/bun.js/scripts/generate-jssink.js) | 5 |
5 files changed, 61 insertions, 73 deletions
diff --git a/src/bun.js/bindings/KeyObject.cpp b/src/bun.js/bindings/KeyObject.cpp index d5782779d..8f2e52379 100644 --- a/src/bun.js/bindings/KeyObject.cpp +++ b/src/bun.js/bindings/KeyObject.cpp @@ -1178,7 +1178,6 @@ JSC::EncodedJSValue KeyObject__createPublicKey(JSC::JSGlobalObject* globalObject JSC::EncodedJSValue KeyObject__createSecretKey(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) { - JSValue bufferArg = callFrame->uncheckedArgument(0); auto& vm = lexicalGlobalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); @@ -1194,7 +1193,6 @@ JSC::EncodedJSValue KeyObject__createSecretKey(JSC::JSGlobalObject* lexicalGloba auto type = bufferArgCell->type(); switch (type) { - case DataViewType: case Uint8ArrayType: case Uint8ClampedArrayType: @@ -1236,6 +1234,7 @@ JSC::EncodedJSValue KeyObject__createSecretKey(JSC::JSGlobalObject* lexicalGloba throwException(lexicalGlobalObject, scope, createTypeError(lexicalGlobalObject, "ERR_INVALID_ARG_TYPE: expected Buffer or array-like object"_s)); return JSValue::encode(JSC::jsUndefined()); } + ASSERT_NOT_REACHED(); } JSC::EncodedJSValue KeyObject__Exports(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame) @@ -2071,8 +2070,8 @@ JSC::EncodedJSValue KeyObject__generateKeyPairSync(JSC::JSGlobalObject* lexicalG publicExponentArray[0] = (uint8_t)(publicExponent >> 24); publicExponentArray[1] = (uint8_t)(publicExponent >> 16); publicExponentArray[2] = (uint8_t)(publicExponent >> 8); - publicExponentArray[3] = (uint8_t)publicExponent; - + publicExponentArray[3] = (uint8_t)publicExponent; + int modulusLength = modulusLengthJS.toUInt32(lexicalGlobalObject); auto returnValue = JSC::JSValue {}; auto keyPairCallback = [&](CryptoKeyPair&& pair) { @@ -2107,17 +2106,17 @@ JSC::EncodedJSValue KeyObject__generateKeyPairSync(JSC::JSGlobalObject* lexicalG } auto namedCurve = namedCurveJS.toWTFString(lexicalGlobalObject); RETURN_IF_EXCEPTION(scope, encodedJSValue()); - if(namedCurve == "P-384"_s || namedCurve == "p384"_s || namedCurve == "secp384r1"_s) { + if (namedCurve == "P-384"_s || namedCurve == "p384"_s || namedCurve == "secp384r1"_s) { namedCurve = "P-384"_s; - } else if(namedCurve == "P-256"_s || namedCurve == "p256"_s || namedCurve == "prime256v1"_s) { + } else if (namedCurve == "P-256"_s || namedCurve == "p256"_s || namedCurve == "prime256v1"_s) { namedCurve = "P-256"_s; - } else if(namedCurve == "P-521"_s || namedCurve == "p521"_s || namedCurve == "secp521r1"_s) { + } else if (namedCurve == "P-521"_s || namedCurve == "p521"_s || namedCurve == "secp521r1"_s) { namedCurve = "P-521"_s; - }else { + } else { throwException(lexicalGlobalObject, scope, createTypeError(lexicalGlobalObject, "curve not supported"_s)); - return JSValue::encode(JSC::jsUndefined()); + return JSValue::encode(JSC::jsUndefined()); } - + auto result = CryptoKeyEC::generatePair(CryptoAlgorithmIdentifier::ECDSA, namedCurve, true, CryptoKeyUsageSign | CryptoKeyUsageVerify); if (result.hasException()) { WebCore::propagateException(*lexicalGlobalObject, scope, result.releaseException()); diff --git a/src/bun.js/bindings/Path.cpp b/src/bun.js/bindings/Path.cpp index 6507b7122..83b080545 100644 --- a/src/bun.js/bindings/Path.cpp +++ b/src/bun.js/bindings/Path.cpp @@ -57,69 +57,69 @@ using namespace JSC; // clang-format on -static JSC_DECLARE_HOST_FUNCTION(Path_functionBasename); -static JSC_DEFINE_HOST_FUNCTION(Path_functionBasename, +JSC_DECLARE_HOST_FUNCTION(Path_functionBasename); +JSC_DEFINE_HOST_FUNCTION(Path_functionBasename, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__basename); } -static JSC_DECLARE_HOST_FUNCTION(Path_functionDirname); -static JSC_DEFINE_HOST_FUNCTION(Path_functionDirname, +JSC_DECLARE_HOST_FUNCTION(Path_functionDirname); +JSC_DEFINE_HOST_FUNCTION(Path_functionDirname, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__dirname); } -static JSC_DECLARE_HOST_FUNCTION(Path_functionExtname); -static JSC_DEFINE_HOST_FUNCTION(Path_functionExtname, +JSC_DECLARE_HOST_FUNCTION(Path_functionExtname); +JSC_DEFINE_HOST_FUNCTION(Path_functionExtname, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__extname); } -static JSC_DECLARE_HOST_FUNCTION(Path_functionFormat); -static JSC_DEFINE_HOST_FUNCTION(Path_functionFormat, +JSC_DECLARE_HOST_FUNCTION(Path_functionFormat); +JSC_DEFINE_HOST_FUNCTION(Path_functionFormat, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__format); } -static JSC_DECLARE_HOST_FUNCTION(Path_functionIsAbsolute); -static JSC_DEFINE_HOST_FUNCTION(Path_functionIsAbsolute, +JSC_DECLARE_HOST_FUNCTION(Path_functionIsAbsolute); +JSC_DEFINE_HOST_FUNCTION(Path_functionIsAbsolute, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__isAbsolute); } -static JSC_DECLARE_HOST_FUNCTION(Path_functionJoin); -static JSC_DEFINE_HOST_FUNCTION(Path_functionJoin, +JSC_DECLARE_HOST_FUNCTION(Path_functionJoin); +JSC_DEFINE_HOST_FUNCTION(Path_functionJoin, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__join); } -static JSC_DECLARE_HOST_FUNCTION(Path_functionNormalize); -static JSC_DEFINE_HOST_FUNCTION(Path_functionNormalize, +JSC_DECLARE_HOST_FUNCTION(Path_functionNormalize); +JSC_DEFINE_HOST_FUNCTION(Path_functionNormalize, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__normalize); } -static JSC_DECLARE_HOST_FUNCTION(Path_functionParse); -static JSC_DEFINE_HOST_FUNCTION(Path_functionParse, +JSC_DECLARE_HOST_FUNCTION(Path_functionParse); +JSC_DEFINE_HOST_FUNCTION(Path_functionParse, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__parse); } -static JSC_DECLARE_HOST_FUNCTION(Path_functionRelative); -static JSC_DEFINE_HOST_FUNCTION(Path_functionRelative, +JSC_DECLARE_HOST_FUNCTION(Path_functionRelative); +JSC_DEFINE_HOST_FUNCTION(Path_functionRelative, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__relative); } -static JSC_DECLARE_HOST_FUNCTION(Path_functionResolve); -static JSC_DEFINE_HOST_FUNCTION(Path_functionResolve, +JSC_DECLARE_HOST_FUNCTION(Path_functionResolve); +JSC_DEFINE_HOST_FUNCTION(Path_functionResolve, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__resolve); } -static JSC_DECLARE_HOST_FUNCTION(Path_functionToNamespacedPath); -static JSC_DEFINE_HOST_FUNCTION(Path_functionToNamespacedPath, +JSC_DECLARE_HOST_FUNCTION(Path_functionToNamespacedPath); +JSC_DEFINE_HOST_FUNCTION(Path_functionToNamespacedPath, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { auto argCount = static_cast<uint16_t>(callFrame->argumentCount()); diff --git a/src/bun.js/webcore/streams.classes.ts b/src/bun.js/webcore/streams.classes.ts deleted file mode 100644 index 0b070b857..000000000 --- a/src/bun.js/webcore/streams.classes.ts +++ /dev/null @@ -1,5 +0,0 @@ -// import { define } from "../scripts/class-definitions"; - -// export default [ -// define({}) -// ] diff --git a/src/bun.js/scripts/generate-classes.ts b/src/codegen/generate-classes.ts index ae28f4fe5..4154d334a 100644 --- a/src/bun.js/scripts/generate-classes.ts +++ b/src/codegen/generate-classes.ts @@ -2,7 +2,7 @@ import { unlinkSync } from "fs"; import { readdirSync } from "fs"; import { resolve } from "path"; -import type { Field, ClassDefinition } from "./class-definitions"; +import type { Field, ClassDefinition } from "../bun.js/scripts/class-definitions"; const CommonIdentifiers = { "name": true, @@ -284,26 +284,6 @@ export function generateHashTable(nameToUse, symbolName, typeName, obj, props = rows.push(propRow(symbolName, typeName, name, props[name], wrapped, defaultPropertyAttributes)); } - // static const HashTableValue JSWebSocketPrototypeTableValues[] = { - // { "constructor"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsWebSocketConstructor, 0 } }, - // { "URL"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsWebSocket_URL, 0 } }, - // { "url"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsWebSocket_url, 0 } }, - // { "readyState"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsWebSocket_readyState, 0 } }, - // { "bufferedAmount"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsWebSocket_bufferedAmount, 0 } }, - // { "onopen"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsWebSocket_onopen, setJSWebSocket_onopen } }, }, - // { "onmessage"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsWebSocket_onmessage, setJSWebSocket_onmessage } }, }, - // { "onerror"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsWebSocket_onerror, setJSWebSocket_onerror } }, }, - // { "onclose"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsWebSocket_onclose, setJSWebSocket_onclose } }, }, - // { "protocol"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsWebSocket_protocol, 0 } }, - // { "extensions"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsWebSocket_extensions, 0 } }, - // { "binaryType"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsWebSocket_binaryType, setJSWebSocket_binaryType } }, }, - // { "send"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsWebSocketPrototypeFunction_send (intptr_t)(1) } }, - // { "close"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsWebSocketPrototypeFunction_close (intptr_t)(0) } }, - // { "CONNECTING"_s, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { HashTableValue::ConstantType, 0 } }, - // { "OPEN"_s, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { HashTableValue::ConstantType, 1 } }, - // { "CLOSING"_s, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { HashTableValue::ConstantType, 2 } }, - // { "CLOSED"_s, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { HashTableValue::ConstantType, 3 } }, - // }; return ` static const HashTableValue ${nameToUse}TableValues[] = {${rows.length > 0 ? "\n" + rows.join(" ,\n") + "\n" : ""}}; `; @@ -1714,7 +1694,7 @@ pub const StaticCallbackType = fn(*JSC.JSGlobalObject, *JSC.CallFrame) callconv( `; -function findClasses() { +function findClassesOldBehavior() { var classes = []; for (let directory of directoriesToSearch) { readdirSync(directory).forEach(file => { @@ -1734,7 +1714,23 @@ function findClasses() { return classes; } -const classes = findClasses(); +function findClasses(argv: string[]) { + const classes = []; + for (const file of argv) { + const result = require(file); + if (!(result?.default?.length ?? 0)) continue; + console.log("Found", result.default.length, "classes from", file); + for (let { name } of result.default) { + console.log(` - ${name}`); + } + + classes.push(...result.default); + } + classes.sort((a, b) => (a.name < b.name ? -1 : 1)); + return classes; +} + +const classes = process.argv.length > 2 ? findClasses(process.argv.slice(2)) : findClassesOldBehavior(); function writeAndUnlink(path, content) { try { @@ -1815,13 +1811,12 @@ function writeCppSerializers() { } `; - for (let klass of classes) { - } - return output; } -await writeAndUnlink(`${import.meta.dir}/../bindings/generated_classes.zig`, [ +const bindingDir = `${import.meta.dir}/../bun.js/bindings`; + +await writeAndUnlink(`${bindingDir}/generated_classes.zig`, [ ZIG_GENERATED_CLASSES_HEADER, ...classes.map(a => generateZig(a.name, a).trim()).join("\n"), @@ -1834,26 +1829,26 @@ comptime { `, ]); const allHeaders = classes.map(a => generateHeader(a.name, a)); -await writeAndUnlink(`${import.meta.dir}/../bindings/ZigGeneratedClasses.h`, [ +await writeAndUnlink(`${bindingDir}/ZigGeneratedClasses.h`, [ GENERATED_CLASSES_HEADER[0], ...[...new Set(extraIncludes.map(a => `#include "${a}";` + "\n"))], GENERATED_CLASSES_HEADER[1], ...allHeaders, GENERATED_CLASSES_FOOTER, ]); -await writeAndUnlink(`${import.meta.dir}/../bindings/ZigGeneratedClasses.cpp`, [ +await writeAndUnlink(`${bindingDir}/ZigGeneratedClasses.cpp`, [ GENERATED_CLASSES_IMPL_HEADER, ...classes.map(a => generateImpl(a.name, a)), writeCppSerializers(classes), GENERATED_CLASSES_IMPL_FOOTER, ]); await writeAndUnlink( - `${import.meta.dir}/../bindings/ZigGeneratedClasses+lazyStructureHeader.h`, + `${bindingDir}/ZigGeneratedClasses+lazyStructureHeader.h`, classes.map(a => generateLazyClassStructureHeader(a.name, a)).join("\n"), ); await writeAndUnlink( - `${import.meta.dir}/../bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h`, + `${bindingDir}/ZigGeneratedClasses+DOMClientIsoSubspaces.h`, classes.map(a => [ `std::unique_ptr<GCClient::IsoSubspace> ${clientSubspaceFor(a.name)};`, @@ -1863,7 +1858,7 @@ await writeAndUnlink( ); await writeAndUnlink( - `${import.meta.dir}/../bindings/ZigGeneratedClasses+DOMIsoSubspaces.h`, + `${bindingDir}/ZigGeneratedClasses+DOMIsoSubspaces.h`, classes.map(a => [ `std::unique_ptr<IsoSubspace> ${subspaceFor(a.name)};`, @@ -1873,7 +1868,7 @@ await writeAndUnlink( ); await writeAndUnlink( - `${import.meta.dir}/../bindings/ZigGeneratedClasses+lazyStructureImpl.h`, + `${bindingDir}/ZigGeneratedClasses+lazyStructureImpl.h`, initLazyClasses(classes.map(a => generateLazyClassStructureImpl(a.name, a))) + "\n" + visitLazyClasses(classes), ); diff --git a/src/bun.js/scripts/generate-jssink.js b/src/codegen/generate-jssink.ts index 758b1863b..292a740f8 100644 --- a/src/bun.js/scripts/generate-jssink.js +++ b/src/codegen/generate-jssink.ts @@ -1,7 +1,6 @@ import { resolve } from "path"; const classes = ["ArrayBufferSink", "FileSink", "HTTPResponseSink", "HTTPSResponseSink"]; -const SINK_COUNT = 5; function names(name) { return { @@ -951,5 +950,5 @@ extern "C" void ${name}__onClose(JSC__JSValue controllerValue, JSC__JSValue reas return templ; } -await Bun.write(resolve(import.meta.dir + "/../bindings/JSSink.h"), header()); -await Bun.write(resolve(import.meta.dir + "/../bindings/JSSink.cpp"), await implementation()); +await Bun.write(resolve(import.meta.dir + "/../bun.js/bindings/JSSink.h"), header()); +await Bun.write(resolve(import.meta.dir + "/../bun.js/bindings/JSSink.cpp"), await implementation()); |