Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stub out WebAssembly.{compile|instantiate}Streaming #14221

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bun.js/bindings/ErrorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
44 changes: 37 additions & 7 deletions src/bun.js/bindings/ZigGlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
#include "ErrorCode.h"
#include "v8/shim/GlobalInternals.h"
#include "EventLoopTask.h"
#include <JavaScriptCore/WasmStreamingCompiler.h>

#if ENABLE(REMOTE_INSPECTOR)
#include "JavaScriptCore/RemoteInspectorServer.h"
Expand Down Expand Up @@ -949,9 +950,7 @@ extern "C" bool Zig__GlobalObject__resetModuleRegistryMap(JSC__JSGlobalObject* g
{ \
return WebCore::JS##ConstructorName::getConstructor(vm, JSC::jsCast<Zig::GlobalObject*>(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<Zig::GlobalObject*>(lexicalGlobalObject))); \
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions src/bun.js/bindings/ZigGlobalObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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&);
Expand Down