mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -05:00
fix(ext/node): make next tick queue resilient to Array.prototype
tampering (#24361)
Closes #24358.
This commit is contained in:
parent
67dcd6db51
commit
8d14a9db2f
1 changed files with 5 additions and 3 deletions
|
@ -1,8 +1,8 @@
|
||||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||||
// Copyright Joyent, Inc. and other Node contributors.
|
// Copyright Joyent, Inc. and other Node contributors.
|
||||||
|
|
||||||
// TODO(petamoriken): enable prefer-primordials for node polyfills
|
import { primordials } from "ext:core/mod.js";
|
||||||
// deno-lint-ignore-file prefer-primordials
|
const { ArrayFrom } = primordials;
|
||||||
|
|
||||||
// Currently optimal queue size, tested on V8 6.0 - 6.6. Must be power of two.
|
// Currently optimal queue size, tested on V8 6.0 - 6.6. Must be power of two.
|
||||||
const kSize = 2048;
|
const kSize = 2048;
|
||||||
|
@ -65,7 +65,7 @@ class FixedCircularBuffer {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.bottom = 0;
|
this.bottom = 0;
|
||||||
this.top = 0;
|
this.top = 0;
|
||||||
this.list = new Array(kSize);
|
this.list = ArrayFrom({ __proto__: null, length: kSize });
|
||||||
this.next = null;
|
this.next = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,11 +111,13 @@ export class FixedQueue {
|
||||||
// and sets it as the new main queue.
|
// and sets it as the new main queue.
|
||||||
this.head = this.head.next = new FixedCircularBuffer();
|
this.head = this.head.next = new FixedCircularBuffer();
|
||||||
}
|
}
|
||||||
|
// deno-lint-ignore prefer-primordials -- `push` is a method of `FixedCircularBuffer`
|
||||||
this.head.push(data);
|
this.head.push(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
shift() {
|
shift() {
|
||||||
const tail = this.tail;
|
const tail = this.tail;
|
||||||
|
// deno-lint-ignore prefer-primordials -- `shift` is a method of `FixedCircularBuffer`
|
||||||
const next = tail.shift();
|
const next = tail.shift();
|
||||||
if (tail.isEmpty() && tail.next !== null) {
|
if (tail.isEmpty() && tail.next !== null) {
|
||||||
// If there is another queue, it forms the new tail.
|
// If there is another queue, it forms the new tail.
|
||||||
|
|
Loading…
Add table
Reference in a new issue