GithubHelp home page GithubHelp logo

amasad / debugjs Goto Github PK

View Code? Open in Web Editor NEW
201.0 8.0 14.0 1.56 MB

[Experimental] Lightweight JavaScript VM and stepping debugger in JavaScript

Home Page: http://amasad.me/2014/01/06/building-an-in-browser-javascript-vm-and-debugger-using-generators/

License: Other

JavaScript 99.89% Makefile 0.11%

debugjs's Introduction

debugjs

Lightweight JavaScript VM and stepping debugger in JavaScript.
Demo app
Blog post

Installation

With component(1):

$ component install amasad/debugjs

With npm

$ npm install amasad/debugjs

Or grab dist/bundle.js for a standalone library.

API

debugjs.createDebugger(options)

Creates and returns a Debugger. options will be passed to the Machine constructor. options.sandbox will be passed as the sandbox option -- see Machine

Debugger

new Debugger(machine)

Creates a Debugger on top of the passed machine.

Debugger#addBreakpoints(filename, linenos)

filename string of the filename. liennos array of linenumbers to add breakpoints to.

Debugger#removeBreakpoint(filename, linenos)

filename string of the filename. liennos array of linenumbers to remove breakpoints to.

Debugger#getBreakpoints(filename)

Gets an array of breakpoints on the file filename.

Debugger#getCallStack(options)

Gets a sanitized call stack, with nothing but stack frames. Pass in { raw: true } to get meta call stack info.

Debugger#run()

Runs the code until it hits a breakpoint.

Debugger#stepOver()

Steps over an instruction.

Debugger#stepIn()

Steps into a function call.

Debugger#stepOut()

Steps out of a function call.

Debugger#load(code, filename)

Loads a file of code into the machine.

Debugger#paused()

Boolean for if the machine is paused.

Debugger#halted()

Boolean for if the machine is halted.

Debugger#getCurrentStackFrame()

Current stsack frame.

Machine

new Machine(sandbox, options)

sandbox object with references to be copied into the context. options:

  • iframeParentElement to attach the context iframe to a parent element

Machine#evaluate(code, filename)

Compiles code as file filename and gets it ready to run.

Machine#step()

Steps through the evaluateed code.

Machine#run()

Calls step continuously until machine is halted

Machine#pause()

Will not let run() do anymore steps.

Machine#resume()

run() could continue running.

Machine#getCallStack()

Gets the call stack. Note that this will include meta call stack information, like thunks etc. See Debugger#getCallStack on how to filter non stack frame information.

Machine#getCurrentStackFrame()

Gets the current stack frame

Machine#getState()

Returns an object the latest step information (whether halted and what was yielded).

Machine#getCurrentLoc()

Line and column of the latest instruction ran by the machine.

Machine#paused

Boolean stating if the machine is paused. See pause()

Machine#halted

Boolean stating if the machine has no more instructions to run and is in idle state.

License

AAL. See LICENSE

debugjs's People

Contributors

amasad avatar istarkov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

debugjs's Issues

perf improvements

grab bag for perf improvements. low hanging fruit mostly exhausted with #4 and #2 but one comes to mind:

optimize all the getCallStack calls in the debugger

debug code on the mobile side

Really Nice Job! But this project does not seem to be maintained. Is there any better alternative?
I want to use this to debug code on the mobile side, Do you think it is feasible? Or is there a mature solution now?

No dist in package, can't import in node.js

Tried to use this sweet library in node.js, but failed.

  1. There is no dist directory, so package.json's main property points to a file that doesn't exist.

  2. Even if I try to directly require lib/index.js, I can't because node.js doesn't support ES6 imports.

Also, I can't just run npm run build in the node_module because your toolchain are dev-dependencies.

Ability to step through expressions

This is a great tool! I've been toying with a similar technology, generating nested functions with callbacks even before generators, but run into an issue with expressions that do not have a return type.

Does debugjs have an ability to step through complex expressions? E.g. in this example

  if(param>2 
     && param<5) {
    alert(param);
  }

From a test on debugjs.com it looks like the entire if() condition is checked in a single step.

Document inability to work with to browser APIs that expect a synchonous response?

Nice project! When it comes time for this kind of thing, I think it should be documented that (as far as I know) there's no way both to return control to the browser and to interact correctly with browser APIs that require a synchronous response to an event.

See http://debugjs.com/#-JCxe60NT_PTa7bdDywz

window.addEventListener('mouseup', function() {
  alert("hello");
});

document.querySelector('.clickme').addEventListener('mouseup', function(e) {
  console.log("blocking hello alert...?");
  // stopPropagation won't work if you put a breakpoint in this function
  e.stopPropagation();
});

How would this be built today?

Hey. I'm making a "learn to program" platform. https://tinkr,tech, if you're interested. It's kind of like Replit, but I'm focusing on making the very first steps on the journey as intuitive as possible. Part of that is executing slowly line-by-line.

I started with putting await new Promise(res => setTimeout(() => res(), 1000)) in between every line (video of it working). Functions break it of course, because they're not async. Converting all functions to async seems complicated and fragile. So now looking into yield, but then I need to go through the AST conversion and creating a stack, just like you have.

So my question is - if all you need is a 1sec delay between each JS line of code - how would you implement that today? Obviously we have yield now, but that probably doesn't change the need to go through AST and create a custom execution stack.

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.