mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
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>
This commit is contained in:
parent
4855674857
commit
b2cd254c35
39 changed files with 532 additions and 906 deletions
|
@ -16,14 +16,12 @@ const {
|
|||
ArrayPrototypeShift,
|
||||
DateNow,
|
||||
Error,
|
||||
FunctionPrototype,
|
||||
Map,
|
||||
MapPrototypeGet,
|
||||
MapPrototypeHas,
|
||||
MapPrototypeSet,
|
||||
MathCeil,
|
||||
ObjectKeys,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
Promise,
|
||||
SafeArrayIterator,
|
||||
Set,
|
||||
|
@ -1294,7 +1292,7 @@ function createTestContext(desc) {
|
|||
|
||||
let stepDesc;
|
||||
if (typeof nameOrFnOrOptions === "string") {
|
||||
if (!(ObjectPrototypeIsPrototypeOf(FunctionPrototype, maybeFn))) {
|
||||
if (typeof maybeFn !== "function") {
|
||||
throw new TypeError("Expected function for second argument.");
|
||||
}
|
||||
stepDesc = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue