Skip to content

Instantly share code, notes, and snippets.

@sebmarkbage
Last active August 11, 2020 04:03
Show Gist options
  • Save sebmarkbage/bdefa100f19345229d526d0fdd22830f to your computer and use it in GitHub Desktop.
Save sebmarkbage/bdefa100f19345229d526d0fdd22830f to your computer and use it in GitHub Desktop.

Revisions

  1. sebmarkbage revised this gist May 15, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Custom Stack Frames Semantics.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ The current execution context has a "custom stack" context with two internal slo

    `console.endStack` - Clear the `[[Custom Stack Start]]` and `[[Custom Stack Override]]` stacks.

    `console.log`, `console.warn`, `console.error` etc. - For any function that logs stacks associated with the call. If there is something in the `[[Custom Stack Start]]` slot. Find the current stack from the current execution context. Find the common ancestor between `[[Custom Stack Start]]` and the current stack. Remove all the common ancestors. Replace them with `[[Custom Stack Override]]` in the root of the stack.
    `console.trace`, `console.warn`, `console.error` etc. - For any function that logs stacks associated with the call. If there is something in the `[[Custom Stack Start]]` slot. Find the current stack from the current execution context. Find the common ancestor between `[[Custom Stack Start]]` and the current stack. Remove all the common ancestors. Replace them with `[[Custom Stack Override]]` in the root of the stack.

    If a break point happens, e.g. due to an error being thrown, `debugger` call or custom break points. If there is something in the `[[Custom Stack Start]]` slot, use the same mechanism as `console.log` to determine the current stack to visualize in a debugger instead of the native stack. The `scope` property contains an object. Every "own" property is considered to be a variable with that name in scope of that stack frame. Useful for debugging.

  2. sebmarkbage renamed this gist May 15, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. sebmarkbage renamed this gist May 15, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Examples.js → Example.js
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ function bar(x) {
    stack: [
    {
    name: 'bar',
    fileName: 'bar.js',
    fileName: 'Bar.js',
    lineNumber: 10,
    columnNumber: 5,
    }
    @@ -29,5 +29,5 @@ var continuation = bar(false);
    invokeCallback(continuation);
    // Logs:
    // You must provide the x argument.
    // at foo (Examples.js:3:4)
    // at bar (bar.js:10:5)
    // at foo (Example.js:3:4)
    // at bar (Bar.js:10:5)
  4. sebmarkbage revised this gist May 15, 2017. 2 changed files with 33 additions and 0 deletions.
    File renamed without changes.
    33 changes: 33 additions & 0 deletions Examples.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    function foo(x) {
    if (!x) {
    console.warn('You must provide the x argument.');
    }
    }

    function bar(x) {
    return {
    stack: [
    {
    name: 'bar',
    fileName: 'bar.js',
    lineNumber: 10,
    columnNumber: 5,
    }
    ],
    callback: foo.bind(null, x)
    };
    }

    function invokeCallback(continuation) {
    console.stack(continuation.stack);
    continuation.callback();
    console.endStack();
    }

    var continuation = bar(false);

    invokeCallback(continuation);
    // Logs:
    // You must provide the x argument.
    // at foo (Examples.js:3:4)
    // at bar (bar.js:10:5)
  5. sebmarkbage revised this gist May 15, 2017. 2 changed files with 11 additions and 3 deletions.
    8 changes: 6 additions & 2 deletions API.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,16 @@
    type FrameScope = {
    [key:string]: mixed
    };
    type StackFrame = {
    name?: string,
    fileName?: string,
    lineNumber?: number,
    columnNumber?: number
    columnNumber?: number,
    scope?: FrameScope
    };
    type StackFrames = Array<StackFrame>;
    type ExtendedConsoleAPI = {
    ...ConsoleAPI,
    stack(frames: StackFrames) : void,
    endStack() : void,
    endStack() : void
    };
    6 changes: 5 additions & 1 deletion Semantics.md
    Original file line number Diff line number Diff line change
    @@ -4,4 +4,8 @@ The current execution context has a "custom stack" context with two internal slo

    `console.endStack` - Clear the `[[Custom Stack Start]]` and `[[Custom Stack Override]]` stacks.

    `console.log`, `console.warn`, `console.error` etc. - For any function that logs stacks associated with the call. If there is something in the `[[Custom Stack Start]]` slot. Find the current stack from the current execution context. Find the common ancestor between `[[Custom Stack Start]]` and the current stack. Remove all the common ancestors and replace them with [[Custom Stack Override]].
    `console.log`, `console.warn`, `console.error` etc. - For any function that logs stacks associated with the call. If there is something in the `[[Custom Stack Start]]` slot. Find the current stack from the current execution context. Find the common ancestor between `[[Custom Stack Start]]` and the current stack. Remove all the common ancestors. Replace them with `[[Custom Stack Override]]` in the root of the stack.

    If a break point happens, e.g. due to an error being thrown, `debugger` call or custom break points. If there is something in the `[[Custom Stack Start]]` slot, use the same mechanism as `console.log` to determine the current stack to visualize in a debugger instead of the native stack. The `scope` property contains an object. Every "own" property is considered to be a variable with that name in scope of that stack frame. Useful for debugging.

    TODO: Consider what should happen to `new Error().stack` if the error is created within a custom scope.
  6. sebmarkbage created this gist May 15, 2017.
    12 changes: 12 additions & 0 deletions API.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    type StackFrame = {
    name?: string,
    fileName?: string,
    lineNumber?: number,
    columnNumber?: number
    };
    type StackFrames = Array<StackFrame>;
    type ExtendedConsoleAPI = {
    ...ConsoleAPI,
    stack(frames: StackFrames) : void,
    endStack() : void,
    };
    7 changes: 7 additions & 0 deletions Semantics.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    The current execution context has a "custom stack" context with two internal slots `[[Custom Stack Start]]` and `[[Custom Stack Override]]`.

    `console.stack` - Assert that the first argument is an array. Store the current stack frame context at the VM level (same as `new Error().stack`) in the current execution context's `[[Custom Stack Start]]` slot. Store the first argument array in the current execution context's `[[Custom Stack Override]]` slot.

    `console.endStack` - Clear the `[[Custom Stack Start]]` and `[[Custom Stack Override]]` stacks.

    `console.log`, `console.warn`, `console.error` etc. - For any function that logs stacks associated with the call. If there is something in the `[[Custom Stack Start]]` slot. Find the current stack from the current execution context. Find the common ancestor between `[[Custom Stack Start]]` and the current stack. Remove all the common ancestors and replace them with [[Custom Stack Override]].