Code Monkey home page Code Monkey logo

proposal-debugger-operands's Introduction

Debugger Operands for JS

Bradley Farias

Stage 0

This document proposes adding an optional operand to the DebuggerStatement production of JS.

A guiding example: grouping breakpoints

The following would be an example of allowing a debugging facility to interpret the operand and provide an interface to group breakpoints into logical units.

const log = (v) => {
  debugger { group: 'logging' };
  console.log(v);
};

Why not a meta function.

Presenting this syntax as a meta function would imply that the operand is always evaluated. This proposal leaves it up to the host to determine if it would like to evaluate the operand.

Detecting Debugging facilities

It should be noted that if the operand only runs when the debugging facility is active it potentially exposes this fact to JS code. Steps can be taken that avoid this such as: always evaluating the operand, preventing side effects while evaluating the operand, or never evaluating the operand.

Various libraries already are able to detect the code injection that debugging facilities use so this ability to detect debugging facilities would not be a new feature.

Use cases

Userland breakpoint grouping

const log = (v) => {
  debugger { group: 'logging' };
  console.log(v);
};

This allows debugging facilities to group breakpoints rather than leaving them opaque.

Alternatives

Debugging facilities could read labels of breakpoints to similar effect.

const log = (v) => {
  logging:debugger;
  console.log(v);
};

However this only allows string based naming. With an operand based approach libraries could use Symbols or Objects as a means to be unique.

Userland breakpoint conditions

const route = (httpRequest) => {
  debugger {
    test: () => httpRequest.tracing || !isProduction
  };
  console.log(v);
};

Alternatives

Code can be wrapped in branches to determine if it should fire a breakpoint.

const route = (httpRequest) => {
  if (httpRequest.tracing || !isProduction) {
    debugger;
  }
  console.log(v);
};

In order to reuse this logic the branch must be duplicated, or abstracted to a function call.

const routeA = (httpRequest) => {
  if (httpRequest.tracing || !isProduction) {
    debugger;
  }
  console.log(v);
};
const routeB = (httpRequest) => {
  breakOnTracing(httpRequest);
  console.log(v);
};

Userland debugging assistance

Lots of tools have browser extensions in order to achieve enhanced experiences such as React Devtools. These tools rely on code injection of the main Realm usually and are not able to handle cases where code is not exposed to the main realm. Providing a means for debugging facilities to determine the type of the breakpoint also exposes the possibility for them to read the group of breakpoints and provide extra assistance to the developer.

proposal-debugger-operands's People

Contributors

bfarias-godaddy avatar

Stargazers

azu avatar Saleh Abdel Motaal avatar  avatar  Matthew Phillips avatar Trotyl Yu avatar Hubert Boma Manilla avatar cybai (Haku) avatar himanoa avatar 底なし沼の魔女 avatar snek avatar François REMY avatar Juriy Zaytsev avatar Mauro Bringolf avatar

Watchers

Jordan Harband avatar François REMY avatar Hubert Boma Manilla avatar James Cloos avatar Trotyl Yu avatar  avatar  avatar

proposal-debugger-operands's Issues

Separate protocol spec.

We need to specify the string keys / symbols that are compatible across environments and make a separate spec text.

Should this be done with @decorators?

Wondering if this could be approached as a @decorator (putting aside whether @decorators are applicable in that lexical scope for a second), and what are the trade-offs here. That is, something along the lines of:

function foo() {
  @group("logging")
  debugger;

  @condition(() => httpRequest.tracing || !isProduction)
  debugger;
}

Compared to your other examples.

@littledan fyi

Remote Debugging Serialization Constraint

IoT debuggers can run JS on chip, but run debuggers on a separate host. Any requirements for posting messages between the debugger and the debuggee machine should be able to be serialized properly.

Reentrancy

Need to define limitations of debugger evaluating code that reaches another debugger.

CC: @syg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.