1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
denoland-deno/ext/web/internal.d.ts
Kenta Moriuchi b2cd254c35
fix: strict type check for cross realms (#21669)
Deno v1.39 introduces `vm.runInNewContext`. This may cause problems when
using `Object.prototype.isPrototypeOf` to check built-in types.

```js
import vm from "node:vm";

const err = new Error();
const crossErr = vm.runInNewContext(`new Error()`);

console.assert( !(crossErr instanceof Error) );
console.assert( Object.getPrototypeOf(err) !== Object.getPrototypeOf(crossErr) );
```

This PR changes to check using internal slots solves them.

---

current: 

```
> import vm from "node:vm";
undefined
> vm.runInNewContext(`new Error("message")`)
Error {}
> vm.runInNewContext(`new Date("2018-12-10T02:26:59.002Z")`)
Date {}
```

this PR:

```
> import vm from "node:vm";
undefined
> vm.runInNewContext(`new Error("message")`)
Error: message
    at <anonymous>:1:1
> vm.runInNewContext(`new Date("2018-12-10T02:26:59.002Z")`)
2018-12-10T02:26:59.002Z
```

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-01-04 09:42:38 +05:30

117 lines
3.5 KiB
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
declare module "ext:deno_web/00_infra.js" {
function collectSequenceOfCodepoints(
input: string,
position: number,
condition: (char: string) => boolean,
): {
result: string;
position: number;
};
const ASCII_DIGIT: string[];
const ASCII_UPPER_ALPHA: string[];
const ASCII_LOWER_ALPHA: string[];
const ASCII_ALPHA: string[];
const ASCII_ALPHANUMERIC: string[];
const HTTP_TAB_OR_SPACE: string[];
const HTTP_WHITESPACE: string[];
const HTTP_TOKEN_CODE_POINT: string[];
const HTTP_TOKEN_CODE_POINT_RE: RegExp;
const HTTP_QUOTED_STRING_TOKEN_POINT: string[];
const HTTP_QUOTED_STRING_TOKEN_POINT_RE: RegExp;
const HTTP_TAB_OR_SPACE_PREFIX_RE: RegExp;
const HTTP_TAB_OR_SPACE_SUFFIX_RE: RegExp;
const HTTP_WHITESPACE_PREFIX_RE: RegExp;
const HTTP_WHITESPACE_SUFFIX_RE: RegExp;
function httpTrim(s: string): string;
function regexMatcher(chars: string[]): string;
function byteUpperCase(s: string): string;
function byteLowerCase(s: string): string;
function collectHttpQuotedString(
input: string,
position: number,
extractValue: boolean,
): {
result: string;
position: number;
};
function forgivingBase64Encode(data: Uint8Array): string;
function forgivingBase64Decode(data: string): Uint8Array;
function forgivingBase64UrlEncode(data: Uint8Array | string): string;
function forgivingBase64UrlDecode(data: string): Uint8Array;
function serializeJSValueToJSONString(value: unknown): string;
}
declare module "ext:deno_web/01_dom_exception.js" {
const DOMException: DOMException;
}
declare module "ext:deno_web/01_mimesniff.js" {
interface MimeType {
type: string;
subtype: string;
parameters: Map<string, string>;
}
function parseMimeType(input: string): MimeType | null;
function essence(mimeType: MimeType): string;
function serializeMimeType(mimeType: MimeType): string;
function extractMimeType(
headerValues: string[] | null,
): MimeType | null;
}
declare module "ext:deno_web/02_event.js" {
const EventTarget: typeof EventTarget;
const Event: typeof event;
const ErrorEvent: typeof ErrorEvent;
const CloseEvent: typeof CloseEvent;
const MessageEvent: typeof MessageEvent;
const CustomEvent: typeof CustomEvent;
const ProgressEvent: typeof ProgressEvent;
const PromiseRejectionEvent: typeof PromiseRejectionEvent;
const reportError: typeof reportError;
}
declare module "ext:deno_web/12_location.js" {
function getLocationHref(): string | undefined;
}
declare module "ext:deno_web/05_base64.js" {
function atob(data: string): string;
function btoa(data: string): string;
}
declare module "ext:deno_web/09_file.js" {
function blobFromObjectUrl(url: string): Blob | null;
function getParts(blob: Blob): string[];
const Blob: typeof Blob;
const File: typeof File;
}
declare module "ext:deno_web/06_streams.js" {
const ReadableStream: typeof ReadableStream;
function isReadableStreamDisturbed(stream: ReadableStream): boolean;
function createProxy<T>(stream: ReadableStream<T>): ReadableStream<T>;
}
declare module "ext:deno_web/13_message_port.js" {
type Transferable = {
kind: "messagePort";
data: number;
} | {
kind: "arrayBuffer";
data: number;
};
interface MessageData {
data: Uint8Array;
transferables: Transferable[];
}
}
declare module "ext:deno_web/16_image_data.js" {
const ImageData: typeof ImageData;
}