mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
node:timers fixes (#16855)
This commit is contained in:
@@ -9,6 +9,22 @@ interface PropertyAttribute {
|
||||
privateSymbol?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies what happens when a method is called with `this` set to a value that is not an instance
|
||||
* of the class.
|
||||
*/
|
||||
export enum InvalidThisBehavior {
|
||||
/**
|
||||
* Default. Throws a `TypeError`.
|
||||
*/
|
||||
Throw,
|
||||
/**
|
||||
* Do not call the native implementation; return `undefined`. Some Node.js methods are supposed to
|
||||
* work like this.
|
||||
*/
|
||||
NoOp,
|
||||
}
|
||||
|
||||
export type Field =
|
||||
| ({
|
||||
getter: string;
|
||||
@@ -35,6 +51,7 @@ export type Field =
|
||||
*/
|
||||
length?: number;
|
||||
passThis?: boolean;
|
||||
invalidThisBehavior?: InvalidThisBehavior;
|
||||
DOMJIT?: {
|
||||
returns: string;
|
||||
args?: [string, string] | [string, string, string] | [string] | [];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// @ts-nocheck
|
||||
import path from "path";
|
||||
import type { ClassDefinition, Field } from "./class-definitions";
|
||||
import { InvalidThisBehavior, type ClassDefinition, type Field } from "./class-definitions";
|
||||
import { camelCase, pascalCase, writeIfNotChanged } from "./helpers";
|
||||
import jsclasses from "./../bun.js/bindings/js_classes";
|
||||
|
||||
@@ -1163,6 +1163,7 @@ JSC_DEFINE_CUSTOM_SETTER(${symbolName(typeName, name)}SetterWrap, (JSGlobalObjec
|
||||
|
||||
if ("fn" in proto[name]) {
|
||||
const fn = proto[name].fn;
|
||||
const invalidThisBehavior = proto[name].invalidThisBehavior ?? InvalidThisBehavior.Throw;
|
||||
rows.push(`
|
||||
JSC_DEFINE_HOST_FUNCTION(${symbolName(typeName, name)}Callback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
|
||||
{
|
||||
@@ -1172,8 +1173,13 @@ JSC_DEFINE_HOST_FUNCTION(${symbolName(typeName, name)}Callback, (JSGlobalObject
|
||||
${className(typeName)}* thisObject = jsDynamicCast<${className(typeName)}*>(callFrame->thisValue());
|
||||
|
||||
if (UNLIKELY(!thisObject)) {
|
||||
scope.throwException(lexicalGlobalObject, Bun::createInvalidThisError(lexicalGlobalObject, callFrame->thisValue(), "${typeName}"_s));
|
||||
return {};
|
||||
${
|
||||
invalidThisBehavior == InvalidThisBehavior.Throw
|
||||
? `
|
||||
scope.throwException(lexicalGlobalObject, Bun::createInvalidThisError(lexicalGlobalObject, callFrame->thisValue(), "${typeName}"_s));
|
||||
return {};`
|
||||
: `return JSValue::encode(JSC::jsUndefined());`
|
||||
}
|
||||
}
|
||||
|
||||
JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
|
||||
|
||||
Reference in New Issue
Block a user