aboutsummaryrefslogtreecommitdiff
path: root/src/javascript/jsc/bindings/ZigGlobalObject.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-17 20:42:28 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-17 20:42:28 -0700
commit9737c01058c632f6764f6e6e78404ee97b33f634 (patch)
tree9486ca5283404f4eb4b3152a63abf89ba3d2c832 /src/javascript/jsc/bindings/ZigGlobalObject.cpp
parent2a3438186af74d23e16125ca33eba7011fb8bd1f (diff)
downloadbun-9737c01058c632f6764f6e6e78404ee97b33f634.tar.gz
bun-9737c01058c632f6764f6e6e78404ee97b33f634.tar.zst
bun-9737c01058c632f6764f6e6e78404ee97b33f634.zip
[bun.js] Implement `self.reportError`
Diffstat (limited to 'src/javascript/jsc/bindings/ZigGlobalObject.cpp')
-rw-r--r--src/javascript/jsc/bindings/ZigGlobalObject.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/javascript/jsc/bindings/ZigGlobalObject.cpp b/src/javascript/jsc/bindings/ZigGlobalObject.cpp
index 16d4786a3..6dca86aa6 100644
--- a/src/javascript/jsc/bindings/ZigGlobalObject.cpp
+++ b/src/javascript/jsc/bindings/ZigGlobalObject.cpp
@@ -540,13 +540,30 @@ static JSC_DEFINE_HOST_FUNCTION(functionImportMeta__resolve,
}
}
+extern "C" void Bun__reportError(JSC::JSGlobalObject*, JSC__JSValue);
+static JSC_DECLARE_HOST_FUNCTION(functionReportError);
+static JSC_DEFINE_HOST_FUNCTION(functionReportError,
+ (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
+{
+ switch (callFrame->argumentCount()) {
+ case 0: {
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+ default: {
+ Bun__reportError(globalObject, JSC::JSValue::encode(callFrame->argument(0)));
+ }
+ }
+
+ return JSC::JSValue::encode(JSC::jsUndefined());
+}
+
// This is not a publicly exposed API currently.
// This is used by the bundler to make Response, Request, FetchEvent,
// and any other objects available globally.
void GlobalObject::installAPIGlobals(JSClassRef* globals, int count)
{
WTF::Vector<GlobalPropertyInfo> extraStaticGlobals;
- extraStaticGlobals.reserveCapacity((size_t)count + 3 + 7);
+ extraStaticGlobals.reserveCapacity((size_t)count + 3 + 9);
int i = 0;
for (; i < count - 1; i++) {
@@ -629,6 +646,12 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count)
JSC::JSFunction::create(vm(), JSC::jsCast<JSC::JSGlobalObject*>(this), 0,
"btoa", functionBTOA),
JSC::PropertyAttribute::DontDelete | 0 });
+ JSC::Identifier reportErrorIdentifier = JSC::Identifier::fromString(vm(), "reportError"_s);
+ extraStaticGlobals.uncheckedAppend(
+ GlobalPropertyInfo { reportErrorIdentifier,
+ JSC::JSFunction::create(vm(), JSC::jsCast<JSC::JSGlobalObject*>(this), 0,
+ "reportError", functionReportError),
+ JSC::PropertyAttribute::DontDelete | 0 });
auto clientData = Bun::clientData(vm());