Skip to content

Commit

Permalink
use primordials
Browse files Browse the repository at this point in the history
  • Loading branch information
khrj committed Nov 23, 2022
1 parent 9974b64 commit 622528b
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
"use strict";

// Disables setting `__proto__` and emits a warning instead, for security reasons.
// https://tc39.es/ecma262/#sec-get-object.prototype.__proto__
// deno-lint-ignore prefer-primordials
Object.defineProperty(Object.prototype, "__proto__", {
configurable: true,
enumerable: false,
get() {
// deno-lint-ignore prefer-primordials
return Object.getPrototypeOf(this);
},
set(_) {
console.warn(
"Prototype access via __proto__ attempted; __proto__ is not implemented in Deno due to security reasons. Use Object.setPrototypeOf instead.",
);
},
});

// Remove Intl.v8BreakIterator because it is a non-standard API.
delete Intl.v8BreakIterator;

Expand All @@ -38,6 +21,8 @@ delete Intl.v8BreakIterator;
ObjectDefineProperty,
ObjectDefineProperties,
ObjectFreeze,
ObjectGetPrototypeOf,
ObjectPrototype,
ObjectPrototypeIsPrototypeOf,
ObjectSetPrototypeOf,
PromiseResolve,
Expand Down Expand Up @@ -86,6 +71,21 @@ delete Intl.v8BreakIterator;
setLanguage,
} = window.__bootstrap.globalScope;

// Disables setting `__proto__` and emits a warning instead, for security reasons.
// https://tc39.es/ecma262/#sec-get-object.prototype.__proto__
ObjectDefineProperty(ObjectPrototype, "__proto__", {
configurable: true,
enumerable: false,
get() {
return ObjectGetPrototypeOf(this);
},
set(_) {
console.warn(
"Prototype access via __proto__ attempted; __proto__ is not implemented in Deno due to security reasons. Use Object.setPrototypeOf instead.",
);
},
});

let windowIsClosing = false;

function windowClose() {
Expand Down Expand Up @@ -240,7 +240,9 @@ delete Intl.v8BreakIterator;
}`;
} else {
return `Uncaught ${
inspectArgs([error], { colors: !colors.getNoColor() })
inspectArgs([error], {
colors: !colors.getNoColor(),
})
}`;
}
}
Expand Down Expand Up @@ -352,16 +354,16 @@ delete Intl.v8BreakIterator;
return false;
}

return !!globalThis.onunhandledrejection ||
eventTarget.listenerCount(globalThis, "unhandledrejection") > 0;
return (
!!globalThis.onunhandledrejection ||
eventTarget.listenerCount(globalThis, "unhandledrejection") > 0
);
}

function promiseRejectMacrotaskCallback() {
while (pendingRejections.length > 0) {
const promise = ArrayPrototypeShift(pendingRejections);
const hasPendingException = ops.op_has_pending_promise_exception(
promise,
);
const hasPendingException = ops.op_has_pending_promise_exception(promise);
const reason = WeakMapPrototypeGet(pendingRejectionsReasons, promise);
WeakMapPrototypeDelete(pendingRejectionsReasons, promise);

Expand Down Expand Up @@ -536,11 +538,7 @@ delete Intl.v8BreakIterator;
util.log("args", runtimeOptions.args);
}

function bootstrapWorkerRuntime(
runtimeOptions,
name,
internalName,
) {
function bootstrapWorkerRuntime(runtimeOptions, name, internalName) {
if (hasBootstrapped) {
throw new Error("Worker runtime already bootstrapped");
}
Expand Down Expand Up @@ -595,10 +593,7 @@ delete Intl.v8BreakIterator;
workerClose();
});

runtimeStart(
runtimeOptions,
internalName ?? name,
);
runtimeStart(runtimeOptions, internalName ?? name);

location.setLocationHref(runtimeOptions.location);

Expand Down

0 comments on commit 622528b

Please sign in to comment.