From 8bbcb5006ebf77a7944472eb2e4a0604f7bbc733 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 27 Mar 2022 23:44:21 -0700 Subject: [PATCH] [Bun.js] Add `DOMException` --- .../jsc/bindings/ZigGlobalObject.cpp | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/javascript/jsc/bindings/ZigGlobalObject.cpp b/src/javascript/jsc/bindings/ZigGlobalObject.cpp index c62457c322..5550b7de91 100644 --- a/src/javascript/jsc/bindings/ZigGlobalObject.cpp +++ b/src/javascript/jsc/bindings/ZigGlobalObject.cpp @@ -79,6 +79,7 @@ #include "JSDOMURL.h" #include "JSURLSearchParams.h" +#include "JSDOMException.h" #include "Process.h" @@ -321,6 +322,17 @@ JSC_DEFINE_CUSTOM_GETTER(JSURLSearchParams_getter, WebCore::JSURLSearchParams::getConstructor(JSC::getVM(lexicalGlobalObject), thisObject)); } +JSC_DECLARE_CUSTOM_GETTER(JSDOMException_getter); + +JSC_DEFINE_CUSTOM_GETTER(JSDOMException_getter, + (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, + JSC::PropertyName)) +{ + Zig::GlobalObject* thisObject = JSC::jsCast(lexicalGlobalObject); + return JSC::JSValue::encode( + WebCore::JSDOMException::getConstructor(JSC::getVM(lexicalGlobalObject), thisObject)); +} + static JSC_DECLARE_CUSTOM_SETTER(property_lazyProcessSetter); static JSC_DECLARE_CUSTOM_GETTER(property_lazyProcessGetter); @@ -725,21 +737,20 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm "reportError", functionReportError), JSC::PropertyAttribute::DontDelete | 0 }); - JSC::Identifier URLConstructor = JSC::Identifier::fromString(vm, "URL"_s); - extraStaticGlobals.uncheckedAppend( - GlobalPropertyInfo { reportErrorIdentifier, - JSC::JSFunction::create(vm, JSC::jsCast(globalObject()), 0, - "reportError", functionReportError), - JSC::PropertyAttribute::DontDelete | 0 }); - this->addStaticGlobals(extraStaticGlobals.data(), extraStaticGlobals.size()); + putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "process"), JSC::CustomGetterSetter::create(vm, property_lazyProcessGetter, property_lazyProcessSetter), + JSC::PropertyAttribute::CustomAccessor | 0); + putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "URL"), JSC::CustomGetterSetter::create(vm, JSDOMURL_getter, nullptr), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "URLSearchParams"), JSC::CustomGetterSetter::create(vm, JSURLSearchParams_getter, nullptr), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); + putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "DOMException"), JSC::CustomGetterSetter::create(vm, JSDOMException_getter, nullptr), + JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); + extraStaticGlobals.releaseBuffer(); }