Compare commits

...

1 Commits

Author SHA1 Message Date
Meghan Denny
d22ab432f9 stub out WebAssembly.{compile|instantiate}Streaming 2024-09-27 18:10:03 -07:00
3 changed files with 41 additions and 7 deletions

View File

@@ -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"],

View File

@@ -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"
@@ -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))); \
}
@@ -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)
{

View File

@@ -194,6 +194,9 @@ public:
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&);