summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/polyfills/internal')
-rw-r--r--ext/node/polyfills/internal/errors.ts6
-rw-r--r--ext/node/polyfills/internal/util.mjs36
2 files changed, 38 insertions, 4 deletions
diff --git a/ext/node/polyfills/internal/errors.ts b/ext/node/polyfills/internal/errors.ts
index a16656087..cb4119411 100644
--- a/ext/node/polyfills/internal/errors.ts
+++ b/ext/node/polyfills/internal/errors.ts
@@ -349,9 +349,8 @@ export class NodeErrorAbstraction extends Error {
super(message);
this.code = code;
this.name = name;
- //This number changes depending on the name of this class
- //20 characters as of now
- this.stack = this.stack && `${name} [${this.code}]${this.stack.slice(20)}`;
+ this.stack = this.stack &&
+ `${name} [${this.code}]${this.stack.slice(this.name.length)}`;
}
override toString() {
@@ -614,7 +613,6 @@ export class ERR_INVALID_ARG_TYPE_RANGE extends NodeRangeError {
export class ERR_INVALID_ARG_TYPE extends NodeTypeError {
constructor(name: string, expected: string | string[], actual: unknown) {
const msg = createInvalidArgType(name, expected);
-
super("ERR_INVALID_ARG_TYPE", `${msg}.${invalidArgTypeHelper(actual)}`);
}
diff --git a/ext/node/polyfills/internal/util.mjs b/ext/node/polyfills/internal/util.mjs
index 596599859..e6b32d17d 100644
--- a/ext/node/polyfills/internal/util.mjs
+++ b/ext/node/polyfills/internal/util.mjs
@@ -15,6 +15,10 @@ import {
} from "ext:deno_node/internal/primordials.mjs";
import { ERR_UNKNOWN_SIGNAL } from "ext:deno_node/internal/errors.ts";
import { os } from "ext:deno_node/internal_binding/constants.ts";
+import { primordials } from "ext:core/mod.js";
+const {
+ SafeWeakRef,
+} = primordials;
export const customInspectSymbol = Symbol.for("nodejs.util.inspect.custom");
export const kEnumerableProperty = Object.create(null);
@@ -135,6 +139,38 @@ export function convertToValidSignal(signal) {
throw new ERR_UNKNOWN_SIGNAL(signal);
}
+export class WeakReference {
+ #weak = null;
+ #strong = null;
+ #refCount = 0;
+ constructor(object) {
+ this.#weak = new SafeWeakRef(object);
+ }
+
+ incRef() {
+ this.#refCount++;
+ if (this.#refCount === 1) {
+ const derefed = this.#weak.deref();
+ if (derefed !== undefined) {
+ this.#strong = derefed;
+ }
+ }
+ return this.#refCount;
+ }
+
+ decRef() {
+ this.#refCount--;
+ if (this.#refCount === 0) {
+ this.#strong = null;
+ }
+ return this.#refCount;
+ }
+
+ get() {
+ return this.#weak.deref();
+ }
+}
+
promisify.custom = kCustomPromisifiedSymbol;
export default {