Giter Site home page Giter Site logo

cmallocfree / jsdebugger Goto Github PK

View Code? Open in Web Editor NEW

This project forked from satanwoo/jsdebugger

0.0 2.0 0.0 413 KB

JavaScript-Based Debugger For Inspecting Running State Of Your Application

Home Page: http://satanwoo.github.io

License: GNU General Public License v3.0

Ruby 1.49% Objective-C 87.63% JavaScript 1.45% Objective-C++ 7.78% C 1.63%

jsdebugger's Introduction

JSDebugger

JavaScript-Based Tool For Inspecting Running State Of Your Application

The status of this project is under rapid development and first stable version is v0.5

JSDebugger is a runtime inspecting tool for you to dig into details of your applications or change application logics dynamically.

You have call any Objective-C method at anytime without manually define JSExport!

Usage

Calling Methods

var view = UIView.alloc().init();
var k = NSMutableArray.alloc().init();
view.setBackgroundColor_(UIColor.redColor());

You may notice the method name is to some extent different from Objective-C. To illustrate it more precisely, the following two steps are executed underlying before calling an Objective-C method:

  • All colons are converted to underscores.
  • Each part of the Objective-C selector is concatenated into single string.

For Example:

application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

will be converted into following string:

application_didFinishLaunchingWithOptions_(application, launchOptions)

Variadic Arguments

JSDebugger Support Variadic Arguments with NIL termination

For Example:

var array = NSArray.arrayWithObjects_(1, 2, 3);

Or you can define your own method with variadic arguments

In Objective-C, you define a class method + (void)test:(int)first,...NS_REQUIRES_NIL_TERMINATION in ViewController,

then you call it with following codes:

ViewController.test_(1, 2, 3, 5, 7, 9, 8);

Getter & Setter

view.backgroundColor = UIColor.redColor();
var color = view.backgroundColor();
var bounds = view.bounds();

Getter Is Not Supported. Use Method Instead Of Getter!!!

For Example:

view.backgroundColor;   // It's Wrong

view.backgroundColor(); // It's Correct

JavaScript

The running context of JSDebugger is totally the same as an ordinary JavaScript file. You can do whatever your want in JSDebugger as long as it satisfied the requirement of JavaScript:

var z = 5;

var k = [1, 2, 3];

var z = {name:'haha', age:15, data:k};

Plugin

Excluded from the core functions provided with JSDebugger, we develop plugin mechanism for you to enhance the ability that JSDebugger able to cover.

Choose

Choose aims to provide your with the ability to access any objects on heaps. The function will search all instances that match the class name you provided exactly and return all found results as an array.

For Example, suppose you have a class named XXXViewController

var vc = choose(XXXViewController);

Then you will make some operation on it:

vc.isViewLoaded();
var view = vc.view();
view.backgroundColor = UIColor.orangeColor();

Playground

We provide you with a mechansim to debug instantly with the help of JSDebugger Playground

It's already integrated into JSDebugger. The usage of it is quite simple, suppose you have a test.js on your Desktop.

Follow steps listed below,

  1. include 'JDLocalFileObserver.h' and declare a reference to it.

    @property (nonatomic, strong) JDLocalFileObserver *fileWatcher;

  2. Init it with path to your test.js and file change callback.

     NSString *jsFilePath = @"PathToDesktop/test.js";
     
     if ([[NSFileManager defaultManager] fileExistsAtPath: jsFilePath]) {
         self.fileWatcher = [[JDLocalFileObserver alloc] initWithFilePath: jsFilePath changeBlock:^{
             NSLog(@"[JSDebugger]::found test.js change");
             dispatch_async(dispatch_get_main_queue(), ^{
                 [[JDEngine engine] evaluateScriptAtPath: jsFilePath];
             });
         }];
         [self.fileWatcher start];
     }
    
  3. Now, whenever you change something in your test.js and save it(Command + S), your will find JSDebugger automatically reload the content of test.js and start to evaluate it.

  4. Do not forget to stop the local file watch whenever you don't need it

     [self.fileWatch stop]
    

If you still get confused, just checkout the code in the JSDebuggerDemo.

Example

Checkout demo.js in the JSDebuggerDemo, it shows great detail of what you can do with JSDebugger.

Contribution

  • JunyiXie

Features:

Here we list all features currently supported by JSDebugger:

  • Class Methods
  • Instance Methods
  • Instance Property
  • Custom Setter
  • Playground
  • Data Structes: primitive types, object, class, struct (Partially)
  • Choose
  • Introspect (Partially)
  • Customized Struct
  • Getter
  • VA_LIST
  • Associate Object
  • Block
  • C Pointer

What's Next

An IDE with live Objective-C to JavaScript convertion is under development.
You can really look forward to it!

Reference

The great works listed below inspired me a lot during the development of JSDebugger.

License

Copyright 2018 @SatanWoo

Checkout License

jsdebugger's People

Contributors

satanwoo avatar valiantcat avatar

Watchers

 avatar  avatar

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.