diff options
author | 2023-01-22 19:52:51 -0800 | |
---|---|---|
committer | 2023-01-22 19:52:51 -0800 | |
commit | 4dfc09018fe3fee391afc7b4edc129730bd037b8 (patch) | |
tree | c721e05549c028d5a22d81fbd7362612fb9e1ae3 /src/bun.js/bindings/ZigGlobalObject.cpp | |
parent | 771db64cbe8ce24d9068812c3e00e7a4612e5c04 (diff) | |
download | bun-4dfc09018fe3fee391afc7b4edc129730bd037b8.tar.gz bun-4dfc09018fe3fee391afc7b4edc129730bd037b8.tar.zst bun-4dfc09018fe3fee391afc7b4edc129730bd037b8.zip |
[EventEmitter] Preserve `this` in event emitter callbacks
Diffstat (limited to 'src/bun.js/bindings/ZigGlobalObject.cpp')
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 11b67b433..58497cad4 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -496,7 +496,7 @@ WebCore::ScriptExecutionContext* GlobalObject::scriptExecutionContext() const void GlobalObject::reportUncaughtExceptionAtEventLoop(JSGlobalObject* globalObject, JSC::Exception* exception) { - Bun__reportError(globalObject, JSValue::encode(JSValue(exception))); + Bun__reportUnhandledError(globalObject, JSValue::encode(JSValue(exception))); } void GlobalObject::promiseRejectionTracker(JSGlobalObject* obj, JSC::JSPromise* promise, @@ -2119,7 +2119,6 @@ public: const ClassInfo BunPrimordialsObject::s_info = { "Primordials"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(BunPrimordialsObject) }; -extern "C" void Bun__reportUnhandledError(JSGlobalObject*, EncodedJSValue); JSC_DEFINE_HOST_FUNCTION(jsFunctionPerformMicrotask, (JSGlobalObject * globalObject, CallFrame* callframe)) { auto& vm = globalObject->vm(); @@ -2141,22 +2140,26 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionPerformMicrotask, (JSGlobalObject * globalObj WTF::NakedPtr<JSC::Exception> exceptionPtr; size_t argCount = callframe->argumentCount(); - if (argCount > 1) { - if (JSValue arg0 = callframe->argument(1)) { - arguments.append(arg0); - } - - if (argCount > 2) { - if (JSValue arg1 = callframe->argument(2)) { - arguments.append(arg1); - } - - if (argCount > 3) { - if (JSValue arg2 = callframe->argument(3)) { - arguments.append(arg2); - } - } - } + switch (argCount) { + case 1: { + break; + } + case 2: { + arguments.append(callframe->uncheckedArgument(1)); + break; + } + case 3: { + arguments.append(callframe->uncheckedArgument(1)); + arguments.append(callframe->uncheckedArgument(2)); + break; + } + case 4: { + arguments.append(callframe->uncheckedArgument(1)); + arguments.append(callframe->uncheckedArgument(2)); + arguments.append(callframe->uncheckedArgument(3)); + } + default: + break; } JSC::call(globalObject, job, callData, jsUndefined(), arguments, exceptionPtr); @@ -3323,10 +3326,10 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm dnsObject->putDirectNativeFunction(vm, this, JSC::Identifier::fromString(vm, "lookup"_s), 2, Bun__DNSResolver__lookup, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DontDelete | 0); dnsObject->putDirectNativeFunction(vm, this, JSC::Identifier::fromString(vm, "resolveSrv"_s), 2, Bun__DNSResolver__resolveSrv, ImplementationVisibility::Public, NoIntrinsic, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DontDelete | 0); + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DontDelete | 0); object->putDirect(vm, PropertyName(identifier), dnsObject, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); } - + { JSC::Identifier identifier = JSC::Identifier::fromString(vm, "plugin"_s); JSFunction* pluginFunction = JSFunction::create(vm, this, 1, String("plugin"_s), jsFunctionBunPlugin, ImplementationVisibility::Public, NoIntrinsic); |