diff --git a/src/bun.js/bindings/ErrorCode.ts b/src/bun.js/bindings/ErrorCode.ts index 549225769e8c5..5a247234bc930 100644 --- a/src/bun.js/bindings/ErrorCode.ts +++ b/src/bun.js/bindings/ErrorCode.ts @@ -47,6 +47,7 @@ export default [ ["ERR_INVALID_STATE", Error, "Error"], ["ERR_BUFFER_OUT_OF_BOUNDS", RangeError, "RangeError"], ["ERR_UNKNOWN_SIGNAL", TypeError, "TypeError"], + ["ERR_NOT_IMPLEMENTED", Error, "Error"], // Bun-specific ["ERR_FORMDATA_PARSE_ERROR", TypeError, "TypeError"], diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index f5169df19651c..44a65da4ff621 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -149,6 +149,7 @@ #include "ErrorCode.h" #include "v8/shim/GlobalInternals.h" #include "EventLoopTask.h" +#include #if ENABLE(REMOTE_INSPECTOR) #include "JavaScriptCore/RemoteInspectorServer.h" @@ -949,9 +950,7 @@ extern "C" bool Zig__GlobalObject__resetModuleRegistryMap(JSC__JSGlobalObject* g { \ return WebCore::JS##ConstructorName::getConstructor(vm, JSC::jsCast(lexicalGlobalObject)); \ } \ - JSC_DEFINE_CUSTOM_GETTER(ConstructorName##_getter, \ - (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, \ - JSC::PropertyName)) \ + JSC_DEFINE_CUSTOM_GETTER(ConstructorName##_getter, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) \ { \ return JSC::JSValue::encode(WebCore::JS##ConstructorName::getConstructor(lexicalGlobalObject->vm(), JSC::jsCast(lexicalGlobalObject))); \ } @@ -1016,8 +1015,8 @@ const JSC::GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = { &scriptExecutionStatus, nullptr, // reportViolationForUnsafeEval nullptr, // defaultLanguage - nullptr, // compileStreaming - nullptr, // instantiateStreaming + &compileStreaming, + &instantiateStreaming, &Zig::deriveShadowRealmGlobalObject, nullptr, // codeForEval nullptr, // canCompileStrings @@ -1041,8 +1040,8 @@ const JSC::GlobalObjectMethodTable EvalGlobalObject::s_globalObjectMethodTable = &scriptExecutionStatus, nullptr, // reportViolationForUnsafeEval nullptr, // defaultLanguage - nullptr, // compileStreaming - nullptr, // instantiateStreaming + &compileStreaming, + &instantiateStreaming, &Zig::deriveShadowRealmGlobalObject, nullptr, // codeForEval nullptr, // canCompileStrings @@ -1109,6 +1108,37 @@ WebCore::ScriptExecutionContext* GlobalObject::scriptExecutionContext() const return m_scriptExecutionContext; } +// https://webassembly.github.io/spec/web-api/index.html#compile-a-potential-webassembly-response +static JSC::JSPromise* handleResponseOnStreamingAction(JSC::JSGlobalObject* globalObject, JSC::JSValue source, JSC::Wasm::CompilerMode compilerMode, JSC::JSObject* importObject) +{ + VM& vm = globalObject->vm(); + JSLockHolder lock(vm); + + auto prom = JSPromise::create(vm, globalObject->promiseStructure()); + + switch (compilerMode) { + case JSC::Wasm::CompilerMode::Validation: + prom->reject(globalObject, createError(globalObject, ErrorCode::ERR_NOT_IMPLEMENTED, String("WebAssembly.compileStreaming is not yet implemented in Bun. Track the status & thumbs up the issue: https://github.com/oven-sh/bun/issues/14219"_s))); + break; + case JSC::Wasm::CompilerMode::FullCompile: + prom->reject(globalObject, createError(globalObject, ErrorCode::ERR_NOT_IMPLEMENTED, String("WebAssembly.instantiateStreaming is not yet implemented in Bun. Track the status & thumbs up the issue: https://github.com/oven-sh/bun/issues/14219"_s))); + break; + } + return prom; +} + +JSC::JSPromise* JSDOMGlobalObject::compileStreaming(JSC::JSGlobalObject* globalObject, JSC::JSValue source) +{ + ASSERT(source); + return handleResponseOnStreamingAction(globalObject, source, JSC::Wasm::CompilerMode::Validation, nullptr); +} + +JSC::JSPromise* JSDOMGlobalObject::instantiateStreaming(JSC::JSGlobalObject* globalObject, JSC::JSValue source, JSC::JSObject* importObject) +{ + ASSERT(source); + return handleResponseOnStreamingAction(globalObject, source, JSC::Wasm::CompilerMode::FullCompile, importObject); +} + void GlobalObject::reportUncaughtExceptionAtEventLoop(JSGlobalObject* globalObject, JSC::Exception* exception) { diff --git a/src/bun.js/bindings/ZigGlobalObject.h b/src/bun.js/bindings/ZigGlobalObject.h index 225dea67fff08..bcf9c4001e6c6 100644 --- a/src/bun.js/bindings/ZigGlobalObject.h +++ b/src/bun.js/bindings/ZigGlobalObject.h @@ -194,6 +194,9 @@ class GlobalObject : public Bun::GlobalScope { static void createCallSitesFromFrames(Zig::GlobalObject* globalObject, JSC::JSGlobalObject* lexicalGlobalObject, JSCStackTrace& stackTrace, JSC::JSArray* callSites); void formatStackTrace(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, JSC::JSObject* errorObject, JSC::JSArray* callSites, JSValue prepareStack = JSC::jsUndefined()); + static JSC::JSPromise* compileStreaming(JSC::JSGlobalObject*, JSC::JSValue); + static JSC::JSPromise* instantiateStreaming(JSC::JSGlobalObject*, JSC::JSValue, JSC::JSObject*); + static void reportUncaughtExceptionAtEventLoop(JSGlobalObject*, JSC::Exception*); static JSGlobalObject* deriveShadowRealmGlobalObject(JSGlobalObject* globalObject); static JSC::JSInternalPromise* moduleLoaderImportModule(JSGlobalObject*, JSC::JSModuleLoader*, JSC::JSString* moduleNameValue, JSC::JSValue parameters, const JSC::SourceOrigin&);