From 0cc40a7ca34f17a86cdcb0240e25e021cd2aa3ed Mon Sep 17 00:00:00 2001 From: bcoll Date: Wed, 18 Oct 2023 15:11:40 +0100 Subject: [PATCH] Move `node-internal:inspect` into `node-internal:util` --- src/node/internal/inspect.d.ts | 84 ----------------- src/node/internal/internal_buffer.ts | 6 +- src/node/internal/internal_inspect.ts | 2 +- src/node/internal/internal_types.ts | 2 +- src/node/internal/util.d.ts | 86 +++++++++++++++++ src/workerd/api/node/inspect.c++ | 64 ------------- src/workerd/api/node/inspect.h | 127 -------------------------- src/workerd/api/node/node.h | 3 - src/workerd/api/node/util.c++ | 55 +++++++++++ src/workerd/api/node/util.h | 107 ++++++++++++++++++++++ 10 files changed, 253 insertions(+), 283 deletions(-) delete mode 100644 src/node/internal/inspect.d.ts delete mode 100644 src/workerd/api/node/inspect.c++ delete mode 100644 src/workerd/api/node/inspect.h diff --git a/src/node/internal/inspect.d.ts b/src/node/internal/inspect.d.ts deleted file mode 100644 index 456ceef6181..00000000000 --- a/src/node/internal/inspect.d.ts +++ /dev/null @@ -1,84 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/ban-types */ - -export const kResourceTypeInspect: unique symbol; - -export const ALL_PROPERTIES: 0; -export const ONLY_ENUMERABLE: 1; -export function getOwnNonIndexProperties(value: unknown, filter: typeof ALL_PROPERTIES | typeof ONLY_ENUMERABLE): PropertyKey[]; - -export const kPending: 0; -export const kFulfilled: 1; -export const kRejected: 2; -export interface PromiseDetails { - state: typeof kPending | typeof kFulfilled | typeof kRejected; - result: unknown; -} -export function getPromiseDetails(value: unknown): PromiseDetails | undefined; - -export interface ProxyDetails { - target: unknown; - handler: unknown; -} -export function getProxyDetails(value: unknown): ProxyDetails | undefined; - -export interface PreviewedEntries { - entries: unknown[]; - isKeyValue: boolean; -} -export function previewEntries(value: unknown): PreviewedEntries | undefined; - -export function getConstructorName(value: unknown): string; - -export type TypedArray = - | Uint8Array - | Uint8ClampedArray - | Uint16Array - | Uint32Array - | Int8Array - | Int16Array - | Int32Array - | BigUint64Array - | BigInt64Array - | Float32Array - | Float64Array; - -export function isArrayBufferView(value: unknown): value is ArrayBufferView; -export function isArgumentsObject(value: unknown): value is IArguments; -export function isArrayBuffer(value: unknown): value is ArrayBuffer; -export function isAsyncFunction(value: unknown): value is Function; -export function isBigInt64Array(value: unknown): value is BigInt64Array; -export function isBigIntObject(value: unknown): value is BigInt; -export function isBigUint64Array(value: unknown): value is BigUint64Array; -export function isBooleanObject(value: unknown): value is Boolean; -export function isDataView(value: unknown): value is DataView; -export function isDate(value: unknown): value is Date; -export function isFloat32Array(value: unknown): value is Float32Array; -export function isFloat64Array(value: unknown): value is Float64Array; -export function isGeneratorFunction(value: unknown): value is GeneratorFunction; -export function isGeneratorObject(value: unknown): value is Generator; -export function isInt8Array(value: unknown): value is Int8Array; -export function isInt16Array(value: unknown): value is Int16Array; -export function isInt32Array(value: unknown): value is Int32Array; -export function isMap(value: unknown): value is Map; -export function isMapIterator(value: unknown): value is IterableIterator; -export function isModuleNamespaceObject(value: unknown): boolean; -export function isNativeError(value: unknown): value is Error; -export function isNumberObject(value: unknown): value is Number; -export function isPromise(value: unknown): value is Promise; -export function isProxy(value: unknown): boolean; -export function isRegExp(value: unknown): value is RegExp; -export function isSet(value: unknown): value is Set; -export function isSetIterator(value: unknown): value is IterableIterator; -export function isSharedArrayBuffer(value: unknown): value is SharedArrayBuffer; -export function isStringObject(value: unknown): value is String; -export function isSymbolObject(value: unknown): value is Symbol; -export function isTypedArray(value: unknown): value is TypedArray; -export function isUint8Array(value: unknown): value is Uint8Array; -export function isUint8ClampedArray(value: unknown): value is Uint8ClampedArray; -export function isUint16Array(value: unknown): value is Uint16Array; -export function isUint32Array(value: unknown): value is Uint32Array; -export function isWeakMap(value: unknown): value is WeakMap; -export function isWeakSet(value: unknown): value is WeakSet; -export function isAnyArrayBuffer(value: unknown): value is ArrayBuffer | SharedArrayBuffer; -export function isBoxedPrimitive(value: unknown): value is Number | String | Boolean | BigInt | Symbol; diff --git a/src/node/internal/internal_buffer.ts b/src/node/internal/internal_buffer.ts index 9bf8d3436b8..a5adcd51895 100644 --- a/src/node/internal/internal_buffer.ts +++ b/src/node/internal/internal_buffer.ts @@ -35,7 +35,7 @@ import { validateString, } from 'node-internal:validators'; -import internalInspect from 'node-internal:inspect'; +import internalUtil from 'node-internal:util'; import { InspectOptionsStylized, inspect as utilInspect, @@ -600,9 +600,9 @@ Buffer.prototype.inspect = function inspect(_recurseTimes: number, ctx: InspectO // Inspect special properties as well, if possible. if (ctx) { let extras = false; - const filter = ctx.showHidden ? internalInspect.ALL_PROPERTIES : internalInspect.ONLY_ENUMERABLE; + const filter = ctx.showHidden ? internalUtil.ALL_PROPERTIES : internalUtil.ONLY_ENUMERABLE; const obj: Record = { __proto__: null }; - internalInspect.getOwnNonIndexProperties(this, filter).forEach( + internalUtil.getOwnNonIndexProperties(this, filter).forEach( (key) => { extras = true; obj[key] = this[key]; diff --git a/src/node/internal/internal_inspect.ts b/src/node/internal/internal_inspect.ts index 9a1038b3258..6b6011b6101 100644 --- a/src/node/internal/internal_inspect.ts +++ b/src/node/internal/internal_inspect.ts @@ -29,7 +29,7 @@ /* todo: the following is adopted code, enabling linting one day */ /* eslint-disable */ -import internal from "node-internal:inspect"; +import internal from "node-internal:util"; import { Buffer } from "node-internal:internal_buffer"; import { diff --git a/src/node/internal/internal_types.ts b/src/node/internal/internal_types.ts index e7bd6bfea98..80089f2119e 100644 --- a/src/node/internal/internal_types.ts +++ b/src/node/internal/internal_types.ts @@ -23,7 +23,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -import internal from "node-internal:inspect"; +import internal from "node-internal:util"; export function isCryptoKey(value: unknown): boolean { return value instanceof CryptoKey; diff --git a/src/node/internal/util.d.ts b/src/node/internal/util.d.ts index f06915f9ec4..b137105a375 100644 --- a/src/node/internal/util.d.ts +++ b/src/node/internal/util.d.ts @@ -1,6 +1,10 @@ // Copyright (c) 2017-2022 Cloudflare, Inc. // Licensed under the Apache 2.0 license found in the LICENSE file or at: // https://opensource.org/licenses/Apache-2.0 + +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/ban-types */ + export abstract class MIMEType { public constructor(input: string); public type: string; @@ -21,3 +25,85 @@ export abstract class MIMEParams { public keys(): Iterable; public values(): Iterable; } + +export const kResourceTypeInspect: unique symbol; + +export const ALL_PROPERTIES: 0; +export const ONLY_ENUMERABLE: 1; +export function getOwnNonIndexProperties(value: unknown, filter: typeof ALL_PROPERTIES | typeof ONLY_ENUMERABLE): PropertyKey[]; + +export const kPending: 0; +export const kFulfilled: 1; +export const kRejected: 2; +export interface PromiseDetails { + state: typeof kPending | typeof kFulfilled | typeof kRejected; + result: unknown; +} +export function getPromiseDetails(value: unknown): PromiseDetails | undefined; + +export interface ProxyDetails { + target: unknown; + handler: unknown; +} +export function getProxyDetails(value: unknown): ProxyDetails | undefined; + +export interface PreviewedEntries { + entries: unknown[]; + isKeyValue: boolean; +} +export function previewEntries(value: unknown): PreviewedEntries | undefined; + +export function getConstructorName(value: unknown): string; + +export type TypedArray = + | Uint8Array + | Uint8ClampedArray + | Uint16Array + | Uint32Array + | Int8Array + | Int16Array + | Int32Array + | BigUint64Array + | BigInt64Array + | Float32Array + | Float64Array; + +export function isArrayBufferView(value: unknown): value is ArrayBufferView; +export function isArgumentsObject(value: unknown): value is IArguments; +export function isArrayBuffer(value: unknown): value is ArrayBuffer; +export function isAsyncFunction(value: unknown): value is Function; +export function isBigInt64Array(value: unknown): value is BigInt64Array; +export function isBigIntObject(value: unknown): value is BigInt; +export function isBigUint64Array(value: unknown): value is BigUint64Array; +export function isBooleanObject(value: unknown): value is Boolean; +export function isDataView(value: unknown): value is DataView; +export function isDate(value: unknown): value is Date; +export function isFloat32Array(value: unknown): value is Float32Array; +export function isFloat64Array(value: unknown): value is Float64Array; +export function isGeneratorFunction(value: unknown): value is GeneratorFunction; +export function isGeneratorObject(value: unknown): value is Generator; +export function isInt8Array(value: unknown): value is Int8Array; +export function isInt16Array(value: unknown): value is Int16Array; +export function isInt32Array(value: unknown): value is Int32Array; +export function isMap(value: unknown): value is Map; +export function isMapIterator(value: unknown): value is IterableIterator; +export function isModuleNamespaceObject(value: unknown): boolean; +export function isNativeError(value: unknown): value is Error; +export function isNumberObject(value: unknown): value is Number; +export function isPromise(value: unknown): value is Promise; +export function isProxy(value: unknown): boolean; +export function isRegExp(value: unknown): value is RegExp; +export function isSet(value: unknown): value is Set; +export function isSetIterator(value: unknown): value is IterableIterator; +export function isSharedArrayBuffer(value: unknown): value is SharedArrayBuffer; +export function isStringObject(value: unknown): value is String; +export function isSymbolObject(value: unknown): value is Symbol; +export function isTypedArray(value: unknown): value is TypedArray; +export function isUint8Array(value: unknown): value is Uint8Array; +export function isUint8ClampedArray(value: unknown): value is Uint8ClampedArray; +export function isUint16Array(value: unknown): value is Uint16Array; +export function isUint32Array(value: unknown): value is Uint32Array; +export function isWeakMap(value: unknown): value is WeakMap; +export function isWeakSet(value: unknown): value is WeakSet; +export function isAnyArrayBuffer(value: unknown): value is ArrayBuffer | SharedArrayBuffer; +export function isBoxedPrimitive(value: unknown): value is Number | String | Boolean | BigInt | Symbol; diff --git a/src/workerd/api/node/inspect.c++ b/src/workerd/api/node/inspect.c++ deleted file mode 100644 index 804fe87d2d9..00000000000 --- a/src/workerd/api/node/inspect.c++ +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2017-2022 Cloudflare, Inc. -// Licensed under the Apache 2.0 license found in the LICENSE file or at: -// https://opensource.org/licenses/Apache-2.0 - -#include "inspect.h" -#include - -namespace workerd::api { - -jsg::JsArray InspectModule::getOwnNonIndexProperties(jsg::Lock& js, jsg::JsObject value, - int filter) { - auto propertyFilter = static_cast(filter); - return value.getPropertyNames(js, jsg::KeyCollectionFilter::OWN_ONLY, propertyFilter, - jsg::IndexFilter::SKIP_INDICES); -} - -jsg::Optional InspectModule::getPromiseDetails(jsg::JsValue value) { - auto promise = KJ_UNWRAP_OR_RETURN(value.tryCast(), kj::none); - auto state = promise.state(); - if (state != jsg::PromiseState::PENDING) { - auto result = promise.result(); - return PromiseDetails { .state = state, .result = result }; - } else { - return PromiseDetails { .state = state, .result = kj::none }; - } -} - -jsg::Optional InspectModule::getProxyDetails(jsg::JsValue value) { - auto proxy = KJ_UNWRAP_OR_RETURN(value.tryCast(), kj::none); - auto target = proxy.target(); - auto handler = proxy.handler(); - return ProxyDetails { .target = target, .handler = handler }; -} - -jsg::Optional InspectModule::previewEntries(jsg::JsValue value) { - auto object = KJ_UNWRAP_OR_RETURN(value.tryCast(), kj::none); - bool isKeyValue; - auto entries = object.previewEntries(&isKeyValue); - return PreviewedEntries { .entries = entries, .isKeyValue = isKeyValue }; -} - -jsg::JsString InspectModule::getConstructorName(jsg::Lock& js, jsg::JsObject value) { - return js.str(value.getConstructorName()); -} - -#define V(Type) bool InspectModule::is##Type(jsg::JsValue value) { return value.is##Type(); }; - JS_INSPECT_IS_TYPES(V) -#undef V -bool InspectModule::isAnyArrayBuffer(jsg::JsValue value) { - return value.isArrayBuffer() || value.isSharedArrayBuffer(); -} -bool InspectModule::isBoxedPrimitive(jsg::JsValue value) { - return value.isNumberObject() || - value.isStringObject() || - value.isBooleanObject() || - value.isBigIntObject() || - value.isSymbolObject(); -} - -jsg::Name InspectModule::getResourceTypeInspect(jsg::Lock& js) { - return js.newApiSymbol("kResourceTypeInspect"_kj); -} - -} diff --git a/src/workerd/api/node/inspect.h b/src/workerd/api/node/inspect.h deleted file mode 100644 index 2486ca4e243..00000000000 --- a/src/workerd/api/node/inspect.h +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (c) 2017-2022 Cloudflare, Inc. -// Licensed under the Apache 2.0 license found in the LICENSE file or at: -// https://opensource.org/licenses/Apache-2.0 -#pragma once - -#include - -namespace workerd::api { - -#define JS_INSPECT_IS_TYPES(V) \ - V(ArrayBufferView) \ - V(ArgumentsObject) \ - V(ArrayBuffer) \ - V(AsyncFunction) \ - V(BigInt64Array) \ - V(BigIntObject) \ - V(BigUint64Array) \ - V(BooleanObject) \ - V(DataView) \ - V(Date) \ - V(Float32Array) \ - V(Float64Array) \ - V(GeneratorFunction) \ - V(GeneratorObject) \ - V(Int8Array) \ - V(Int16Array) \ - V(Int32Array) \ - V(Map) \ - V(MapIterator) \ - V(ModuleNamespaceObject) \ - V(NativeError) \ - V(NumberObject) \ - V(Promise) \ - V(Proxy) \ - V(RegExp) \ - V(Set) \ - V(SetIterator) \ - V(SharedArrayBuffer) \ - V(StringObject) \ - V(SymbolObject) \ - V(TypedArray) \ - V(Uint8Array) \ - V(Uint8ClampedArray) \ - V(Uint16Array) \ - V(Uint32Array) \ - V(WeakMap) \ - V(WeakSet) - -// Implements supporting utilities for Node's `util.inspect()` function -class InspectModule final: public jsg::Object { -public: - jsg::Name getResourceTypeInspect(jsg::Lock& js); - - // `getOwnNonIndexProperties()` `filter`s - static constexpr int ALL_PROPERTIES = jsg::PropertyFilter::ALL_PROPERTIES; - static constexpr int ONLY_ENUMERABLE = jsg::PropertyFilter::ONLY_ENUMERABLE; - - jsg::JsArray getOwnNonIndexProperties(jsg::Lock& js, jsg::JsObject value, int filter); - - // `PromiseDetails` `state`s - static constexpr int kPending = jsg::PromiseState::PENDING; - static constexpr int kFulfilled = jsg::PromiseState::FULFILLED; - static constexpr int kRejected = jsg::PromiseState::REJECTED; - - struct PromiseDetails { - int state; // TODO: can we make this a `jsg::PromiseState` - jsg::Optional result; - - JSG_STRUCT(state, result); - }; - jsg::Optional getPromiseDetails(jsg::JsValue value); - - struct ProxyDetails { - jsg::JsValue target; - jsg::JsValue handler; - - JSG_STRUCT(target, handler); - }; - jsg::Optional getProxyDetails(jsg::JsValue value); - - struct PreviewedEntries { - jsg::JsArray entries; - bool isKeyValue; - - JSG_STRUCT(entries, isKeyValue); - }; - jsg::Optional previewEntries(jsg::JsValue value); - - jsg::JsString getConstructorName(jsg::Lock& js, jsg::JsObject value); - -#define V(Type) bool is##Type(jsg::JsValue value); - JS_INSPECT_IS_TYPES(V) -#undef V - bool isAnyArrayBuffer(jsg::JsValue value); - bool isBoxedPrimitive(jsg::JsValue value); - - JSG_RESOURCE_TYPE(InspectModule) { - JSG_READONLY_INSTANCE_PROPERTY(kResourceTypeInspect, getResourceTypeInspect); - - JSG_STATIC_CONSTANT(ALL_PROPERTIES); - JSG_STATIC_CONSTANT(ONLY_ENUMERABLE); - JSG_METHOD(getOwnNonIndexProperties); - - JSG_STATIC_CONSTANT(kPending); - JSG_STATIC_CONSTANT(kFulfilled); - JSG_STATIC_CONSTANT(kRejected); - JSG_METHOD(getPromiseDetails); - - JSG_METHOD(getProxyDetails); - JSG_METHOD(previewEntries); - JSG_METHOD(getConstructorName); - - #define V(Type) JSG_METHOD(is##Type); - JS_INSPECT_IS_TYPES(V) - #undef V - JSG_METHOD(isAnyArrayBuffer); - JSG_METHOD(isBoxedPrimitive); - } -}; - -#define EW_NODE_INSPECT_ISOLATE_TYPES \ - api::InspectModule, \ - api::InspectModule::PromiseDetails, \ - api::InspectModule::ProxyDetails, \ - api::InspectModule::PreviewedEntries - -} diff --git a/src/workerd/api/node/node.h b/src/workerd/api/node/node.h index 2adb3b60e47..e39a06159f3 100644 --- a/src/workerd/api/node/node.h +++ b/src/workerd/api/node/node.h @@ -4,7 +4,6 @@ #include "buffer.h" #include "crypto.h" #include "diagnostics-channel.h" -#include "inspect.h" #include "util.h" #include #include @@ -41,7 +40,6 @@ void registerNodeJsCompatModules( V(AsyncHooksModule, "node-internal:async_hooks") \ V(BufferUtil, "node-internal:buffer") \ V(CryptoImpl, "node-internal:crypto") \ - V(InspectModule, "node-internal:inspect") \ V(UtilModule, "node-internal:util") \ V(DiagnosticsChannelModule, "node-internal:diagnostics_channel") @@ -75,7 +73,6 @@ void registerNodeJsCompatModules( EW_NODE_BUFFER_ISOLATE_TYPES, \ EW_NODE_CRYPTO_ISOLATE_TYPES, \ EW_NODE_DIAGNOSTICCHANNEL_ISOLATE_TYPES, \ - EW_NODE_INSPECT_ISOLATE_TYPES, \ EW_NODE_ASYNCHOOKS_ISOLATE_TYPES, \ EW_NODE_UTIL_ISOLATE_TYPES diff --git a/src/workerd/api/node/util.c++ b/src/workerd/api/node/util.c++ index 35f31db90d7..029e7965598 100644 --- a/src/workerd/api/node/util.c++ +++ b/src/workerd/api/node/util.c++ @@ -127,4 +127,59 @@ kj::String MIMEType::toString() { return inner.toString(); } +jsg::JsArray UtilModule::getOwnNonIndexProperties(jsg::Lock& js, jsg::JsObject value, + int filter) { + auto propertyFilter = static_cast(filter); + return value.getPropertyNames(js, jsg::KeyCollectionFilter::OWN_ONLY, propertyFilter, + jsg::IndexFilter::SKIP_INDICES); +} + +jsg::Optional UtilModule::getPromiseDetails(jsg::JsValue value) { + auto promise = KJ_UNWRAP_OR_RETURN(value.tryCast(), kj::none); + auto state = promise.state(); + if (state != jsg::PromiseState::PENDING) { + auto result = promise.result(); + return PromiseDetails { .state = state, .result = result }; + } else { + return PromiseDetails { .state = state, .result = kj::none }; + } +} + +jsg::Optional UtilModule::getProxyDetails(jsg::JsValue value) { + auto proxy = KJ_UNWRAP_OR_RETURN(value.tryCast(), kj::none); + auto target = proxy.target(); + auto handler = proxy.handler(); + return ProxyDetails { .target = target, .handler = handler }; +} + +jsg::Optional UtilModule::previewEntries(jsg::JsValue value) { + auto object = KJ_UNWRAP_OR_RETURN(value.tryCast(), kj::none); + bool isKeyValue; + auto entries = object.previewEntries(&isKeyValue); + return PreviewedEntries { .entries = entries, .isKeyValue = isKeyValue }; +} + +jsg::JsString UtilModule::getConstructorName(jsg::Lock& js, jsg::JsObject value) { + return js.str(value.getConstructorName()); +} + +#define V(Type) bool UtilModule::is##Type(jsg::JsValue value) { return value.is##Type(); }; + JS_UTIL_IS_TYPES(V) +#undef V +bool UtilModule::isAnyArrayBuffer(jsg::JsValue value) { + return value.isArrayBuffer() || value.isSharedArrayBuffer(); +} +bool UtilModule::isBoxedPrimitive(jsg::JsValue value) { + return value.isNumberObject() || + value.isStringObject() || + value.isBooleanObject() || + value.isBigIntObject() || + value.isSymbolObject(); +} + +jsg::Name UtilModule::getResourceTypeInspect(jsg::Lock& js) { + return js.newApiSymbol("kResourceTypeInspect"_kj); +} + + } // namespace workerd::api::node diff --git a/src/workerd/api/node/util.h b/src/workerd/api/node/util.h index c30d8b142e8..ee6dbfe0a66 100644 --- a/src/workerd/api/node/util.h +++ b/src/workerd/api/node/util.h @@ -104,17 +104,124 @@ class MIMEType final: public jsg::Object { jsg::Ref params; }; +#define JS_UTIL_IS_TYPES(V) \ + V(ArrayBufferView) \ + V(ArgumentsObject) \ + V(ArrayBuffer) \ + V(AsyncFunction) \ + V(BigInt64Array) \ + V(BigIntObject) \ + V(BigUint64Array) \ + V(BooleanObject) \ + V(DataView) \ + V(Date) \ + V(Float32Array) \ + V(Float64Array) \ + V(GeneratorFunction) \ + V(GeneratorObject) \ + V(Int8Array) \ + V(Int16Array) \ + V(Int32Array) \ + V(Map) \ + V(MapIterator) \ + V(ModuleNamespaceObject) \ + V(NativeError) \ + V(NumberObject) \ + V(Promise) \ + V(Proxy) \ + V(RegExp) \ + V(Set) \ + V(SetIterator) \ + V(SharedArrayBuffer) \ + V(StringObject) \ + V(SymbolObject) \ + V(TypedArray) \ + V(Uint8Array) \ + V(Uint8ClampedArray) \ + V(Uint16Array) \ + V(Uint32Array) \ + V(WeakMap) \ + V(WeakSet) + class UtilModule final: public jsg::Object { public: + jsg::Name getResourceTypeInspect(jsg::Lock& js); + + // `getOwnNonIndexProperties()` `filter`s + static constexpr int ALL_PROPERTIES = jsg::PropertyFilter::ALL_PROPERTIES; + static constexpr int ONLY_ENUMERABLE = jsg::PropertyFilter::ONLY_ENUMERABLE; + + jsg::JsArray getOwnNonIndexProperties(jsg::Lock& js, jsg::JsObject value, int filter); + + // `PromiseDetails` `state`s + static constexpr int kPending = jsg::PromiseState::PENDING; + static constexpr int kFulfilled = jsg::PromiseState::FULFILLED; + static constexpr int kRejected = jsg::PromiseState::REJECTED; + + struct PromiseDetails { + int state; // TODO: can we make this a `jsg::PromiseState` + jsg::Optional result; + + JSG_STRUCT(state, result); + }; + jsg::Optional getPromiseDetails(jsg::JsValue value); + + struct ProxyDetails { + jsg::JsValue target; + jsg::JsValue handler; + + JSG_STRUCT(target, handler); + }; + jsg::Optional getProxyDetails(jsg::JsValue value); + + struct PreviewedEntries { + jsg::JsArray entries; + bool isKeyValue; + + JSG_STRUCT(entries, isKeyValue); + }; + jsg::Optional previewEntries(jsg::JsValue value); + + jsg::JsString getConstructorName(jsg::Lock& js, jsg::JsObject value); + +#define V(Type) bool is##Type(jsg::JsValue value); + JS_UTIL_IS_TYPES(V) +#undef V + bool isAnyArrayBuffer(jsg::JsValue value); + bool isBoxedPrimitive(jsg::JsValue value); JSG_RESOURCE_TYPE(UtilModule) { JSG_NESTED_TYPE(MIMEType); JSG_NESTED_TYPE(MIMEParams); + + JSG_READONLY_INSTANCE_PROPERTY(kResourceTypeInspect, getResourceTypeInspect); + + JSG_STATIC_CONSTANT(ALL_PROPERTIES); + JSG_STATIC_CONSTANT(ONLY_ENUMERABLE); + JSG_METHOD(getOwnNonIndexProperties); + + JSG_STATIC_CONSTANT(kPending); + JSG_STATIC_CONSTANT(kFulfilled); + JSG_STATIC_CONSTANT(kRejected); + JSG_METHOD(getPromiseDetails); + + JSG_METHOD(getProxyDetails); + JSG_METHOD(previewEntries); + JSG_METHOD(getConstructorName); + + #define V(Type) JSG_METHOD(is##Type); + JS_UTIL_IS_TYPES(V) + #undef V + JSG_METHOD(isAnyArrayBuffer); + JSG_METHOD(isBoxedPrimitive); } }; #define EW_NODE_UTIL_ISOLATE_TYPES \ api::node::UtilModule, \ + api::node::UtilModule::PromiseDetails, \ + api::node::UtilModule::ProxyDetails, \ + api::node::UtilModule::PreviewedEntries, \ api::node::MIMEType, \ api::node::MIMEParams, \ api::node::MIMEParams::EntryIterator, \