Skip to content

Instantly share code, notes, and snippets.

View TimothyGu's full-sized avatar
🤠
🤠

Timothy Gu TimothyGu

🤠
🤠
  • Seattle, US
  • 19:47 (UTC -07:00)
View GitHub Profile
extend layout.jade
block content
p Content
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>for-of loop vs forEach</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>64bit comparison</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@TimothyGu
TimothyGu / gist:8f930b931a51999b6100cb42b1156153
Created October 8, 2017 22:17
Array with a negative length!
'use strict';
const OriginalArray = global.Array;
global.Array = function Array(...args) {
const arr = new OriginalArray(...args);
let length = arr.length;
return new Proxy(arr, {
set(target, propKey, value, Receiver) {
if (propKey === 'length') {
"use strict";
// Example integration of the new vm.Module API into jsdom.
const vm = require("vm");
const { URL } = require("url");
class ModuleScript {
constructor() {
this.context = null;
'use strict';
const { Module } = require('vm');
process.on('unhandledRejection', p => {
process.nextTick(() => { throw p; });
});
(async () => {
const rootModule = new Module('export default 5;');
'use strict';
const { Module } = require('vm');
process.on('unhandledRejection', p => {
process.nextTick(() => { throw p; });
});
(async () => {
const rootModule = new Module('export default 5;');
diff --git a/lib/internal/vm/Module.js b/lib/internal/vm/Module.js
index c7f90a83a3..806c7ae20f 100644
--- a/lib/internal/vm/Module.js
+++ b/lib/internal/vm/Module.js
@@ -32,6 +32,7 @@ const perContextModuleId = new WeakMap();
const wrapMap = new WeakMap();
const dependencyCacheMap = new WeakMap();
const linkingStatusMap = new WeakMap();
+const linkingStatusDeferredMap = new WeakMap();
"g"
>>> {"id":16,"method":"Runtime.evaluate","params":{"expression":"this","objectGroup":"completion","includeCommandLineAPI":true,"silent":true,"contextId":1,"returnByValue":false,"generatePreview":false,"userGesture":false,"awaitPromise":false,"throwOnSideEffect":false}}
<<< {"id":16,"result":{"result":{"type":"object","className":"global","description":"global","objectId":"{\"injectedScriptId\":1,\"id\":9}"}}}
>>> {"id":17,"method":"Runtime.evaluate","params":{"expression":"g","includeCommandLineAPI":true,"contextId":1,"generatePreview":true,"userGesture":true,"awaitPromise":false,"throwOnSideEffect":true,"timeout":500}}
<<< {"id":17,"result":{"result":{"type":"object","subtype":"error","className":"ReferenceError","description":"ReferenceError: g is not defined\n at <anonymous>:1:1","objectId":"{\"injectedScriptId\":1,\"id\":10}"},"exceptionDetails":{"exceptionId":4,"text":"Uncaught","lineNumber":0,"columnNumber":0,"scriptId":"88","stackTrace":{"callFrames":[{"functionName":"","scriptId":"88","url":"
@TimothyGu
TimothyGu / index.js
Created July 11, 2018 20:19
Firefox #1475000
"use strict";
const http = require("http");
const server = http.createServer((req, res) => {
if (req.url.includes("slow.js")) {
setTimeout(() => {
res.setHeader("Content-Type", "text/javascript");
res.end("void 0;");
}, 5000);