mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 11:59:00 +00:00
[bun.js] Add ShadowRealm
This commit is contained in:
@@ -229,6 +229,25 @@ namespace Zig {
|
||||
const JSC::ClassInfo GlobalObject::s_info = { "GlobalObject", &Base::s_info, nullptr, nullptr,
|
||||
CREATE_METHOD_TABLE(GlobalObject) };
|
||||
|
||||
extern "C" JSClassRef* Zig__getAPIGlobals(size_t* count);
|
||||
|
||||
static JSGlobalObject* deriveShadowRealmGlobalObject(JSGlobalObject* globalObject)
|
||||
{
|
||||
auto& vm = globalObject->vm();
|
||||
Zig::GlobalObject* shadow = Zig::GlobalObject::create(vm, Zig::GlobalObject::createStructure(vm, JSC::jsNull()));
|
||||
shadow->setConsole(shadow);
|
||||
size_t count = 0;
|
||||
JSClassRef* globalObjectClass;
|
||||
globalObjectClass = Zig__getAPIGlobals(&count);
|
||||
|
||||
shadow->setConsole(shadow);
|
||||
if (count > 0) {
|
||||
shadow->installAPIGlobals(globalObjectClass, count);
|
||||
}
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
const JSC::GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = {
|
||||
&supportsRichSourceInfo,
|
||||
&shouldInterruptScript,
|
||||
@@ -247,6 +266,8 @@ const JSC::GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = {
|
||||
nullptr, // defaultLanguage
|
||||
nullptr, // compileStreaming
|
||||
nullptr, // instantiateStreaming
|
||||
nullptr,
|
||||
&Zig::deriveShadowRealmGlobalObject
|
||||
};
|
||||
|
||||
void GlobalObject::reportUncaughtExceptionAtEventLoop(JSGlobalObject* globalObject,
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
}
|
||||
|
||||
static void reportUncaughtExceptionAtEventLoop(JSGlobalObject*, JSC::Exception*);
|
||||
|
||||
static JSGlobalObject* deriveShadowRealmGlobalObject(JSGlobalObject* globalObject);
|
||||
static void queueMicrotaskToEventLoop(JSC::JSGlobalObject& global, Ref<JSC::Microtask>&& task);
|
||||
static JSC::JSInternalPromise* moduleLoaderImportModule(JSGlobalObject*, JSC::JSModuleLoader*,
|
||||
JSC::JSString* moduleNameValue,
|
||||
|
||||
@@ -241,6 +241,12 @@ export fn ZigString__free_global(ptr: [*]const u8, len: usize) void {
|
||||
default_allocator.free(str);
|
||||
}
|
||||
|
||||
export fn Zig__getAPIGlobals(count: *usize) [*]JSC.C.JSClassRef {
|
||||
var globals = JSC.VirtualMachine.getAPIGlobals();
|
||||
count.* = globals.len;
|
||||
return globals.ptr;
|
||||
}
|
||||
|
||||
pub const JSErrorCode = enum(u8) {
|
||||
Error = 0,
|
||||
EvalError = 1,
|
||||
@@ -1855,6 +1861,7 @@ comptime {
|
||||
if (!is_bindgen) {
|
||||
_ = Process.getTitle;
|
||||
_ = Process.setTitle;
|
||||
_ = Zig__getAPIGlobals;
|
||||
std.testing.refAllDecls(NodeReadableStream);
|
||||
std.testing.refAllDecls(Bun.Timer);
|
||||
std.testing.refAllDecls(NodeWritableStream);
|
||||
|
||||
Reference in New Issue
Block a user