Code Monkey home page Code Monkey logo

flutter_jscore's Introduction

Hi there 👋, I'm codiss.

I love to talk on trending ⚡ technology ⚡, stay hungry stay foolish. Connect with me here 邮箱

  • 🚀 I use daily: Dart Flutter Android JavaScript Vue Git Shell Nginx Vite NPM

  • 💻 I work using: VS Code IntelliJ Android Studio Gitee GitHub GitLab macOS Windows

  • ⚙️ I also use and work: IntelliJ Flutter Vue HTML5 CSS3

  • 🌱 I’m currently learning: mpv Flutter Vue Jetpack Compose


You are my Visitor Count visitor, Thank You!🎉🎉

Github Stats


flutter_jscore's People

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

flutter_jscore's Issues

异步调用回调方法崩溃

我这里创建一个test方法,接收一个回调函数。如果我同步触发这个函数可以正常工作。
如果异步触发就直接崩溃了。

class TestBug2 extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
          child: RaisedButton(
        child: Text('TEST2'),
        onPressed: () {
          final jsContext = JSContext.createInGroup();
          jsContext.globalObject.setProperty(
              'test',
              JSObject.makeFunctionWithCallback(
                  jsContext, 'test',
                  Pointer.fromFunction(testFunction)
              ).toValue(),
              JSPropertyAttributes.kJSPropertyAttributeDontDelete);

          jsContext.evaluate('test((n) => n + n)');
        },
      )),
    );
  }

  static Pointer testFunction(
      Pointer ctx,
      Pointer function,
      Pointer thisObject,
      int argumentCount,
      Pointer<Pointer> arguments,
      Pointer<Pointer> exception) {
    final context = JSContext(ctx);

    final jsv = JSValue(context, arguments[0]);
//    jsv.protect();
    // ⬇️同步执行 没有问题直接输出结果
    final data = jsv.toObject().callAsFunction(JSObject(context, thisObject), JSValuePointer(JSValue.makeNumber(context, 2.0).pointer));
    print(data.toNumber());

    // ⬇️模拟异步执行,直接崩溃
    Future.delayed(const Duration(milliseconds: 300), () {
      final data = jsv.toObject().callAsFunction(JSObject(context, thisObject), JSValuePointer(JSValue.makeNumber(context, 2.0).pointer));
      print(data.toNumber());
    });
  }
}

崩溃代码

F/libc    ( 9378): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 9417 (Thread-2), pid 9378 ()
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'google/coral/coral:10/QQ2A.200305.003/6156912:user/release-keys'
Revision: 'MP1.0'
ABI: 'arm64'
Timestamp: 2020-03-17 14:29:15+0800
pid: 9378, tid: 9417, name: Thread-2  >>> com.example.jsrun <<<
uid: 10289
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
Cause: null pointer dereference
    x0  0000006ff2a46c98  x1  0000000000000000  x2  0000006fdc7e5b40  x3  0000006ff2a45f40
    x4  0000006fcd6c2ee0  x5  0000006fdc7e5b40  x6  0000006fd63515e4  x7  0000006fd4cb48f1
    x8  0000006ff2a44000  x9  0000000000000001  x10 0000000000000001  x11 0000007040000000
    x12 0000000000000a00  x13 000000000c4ef110  x14 0000000000000068  x15 0000006ff2a46cc0
    x16 0000000000000000  x17 0000007051dc0970  x18 0000000000000002  x19 0000006fdc7e5b40
    x20 0000000000000000  x21 0000006fcd6c2ee0  x22 0000006ff2a45f40  x23 0000007051d2e2b8
    x24 0000006fe2d80041  x25 0000006ff296e000  x26 0000007051dc0400  x27 0000006fe1187010
    x28 0000000000000004  x29 0000006ff2a46cd8
    sp  0000006ff2a46c80  lr  0000006fd635161c  pc  0000006fd6906e8c
backtrace:
      #00 pc 0000000000680e8c  /data/app/com.example.jsrun-IMKGo_ZTkeXv0aKVB8-Nmw==/lib/arm64/libjsc.so
      #01 pc 00000000000cb618  /data/app/com.example.jsrun-IMKGo_ZTkeXv0aKVB8-Nmw==/lib/arm64/libjsc.so (JSValueToObject+52)
      #02 pc 000000000000485c  <anonymous:6fe2d00000>
Lost connection to device.

Failed to lookup symbol (undefined symbol: JSObjectMakeDeferredPromise)

I want to create a function return promise to javascript, but the code only run to print('2') and got error at JSObject.makeDeferredPromise

 Pointer _getUser(
      Pointer ctx,
      Pointer function,
      Pointer thisObject,
      int argumentCount,
      Pointer<Pointer> arguments,
      Pointer<Pointer> exception) {
    print('getUrl called');
    final resolve = JSObject.makeFunction(
        _jsContext, 'resolve', JSStringPointer.array(['value']), '', '');

    final reject = JSObject.makeFunction(
        _jsContext, 'reject', JSStringPointer.array(['value']), '', '');

    print('2');

    final promise = JSObject.makeDeferredPromise(_jsContext,
        JSObjectPointer(resolve.pointer), JSObjectPointer(reject.pointer));

    print('3');

    return promise.pointer;
  }

both version from pub.dev or git got the error

flutter_jscore:
    git:
      url: https://github.com/xuelongqy/flutter_jscore.git

flutter doctor

[✓] Flutter (Channel stable, 1.22.4, on Mac OS X 10.14.6 darwin-x64,
    locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[!] Android Studio (version 4.1)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.51.1)
[✓] Connected device (1 available)

New_update?

Please update this plugin to support flutter 2 and dart 2.12 and nullsafety

jscore中类的使用问题

我在dart里创建的类,js里初始化后返回到dart再取值发现取到的都是最后一个

js执行的: [new Text('测试1'), new Text('测试2'), new Text('测试3')];
到dart中取到的内容是 (测试3, 测试3, 测试3)
全部变成最后一个了

大佬帮忙看看是不是用的方法不对.

完整代码如下:

class TestBug extends StatelessWidget {

  static Pointer jsClassInitialize(
      Pointer ctx,
      Pointer constructor,
      int argumentCount,
      Pointer<Pointer> arguments,
      Pointer<Pointer> exception) {
    String text;
    final context = JSContext(ctx);
    final that = JSValue(context, constructor).toObject();
    if (argumentCount >= 1) {
      final arg1 = JSValue(context, arguments[0]);
      if (arg1.isString) {
        text = arg1.string;
      }
    }
    that.setProperty(
        'text',
        JSValue.makeString(context, text),
        JSPropertyAttributes.kJSPropertyAttributeDontDelete);
    return constructor;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
          child: RaisedButton(
            child: Text('TEST'),
            onPressed: () {
              final jsContext = JSContext.createInGroup();
              final classDef = JSClassDefinition(
                version: 0,
                attributes: JSClassAttributes.kJSClassAttributeNone,
                className: 'Text',
                callAsConstructor: Pointer.fromFunction(jsClassInitialize),
                staticFunctions: [],
              );
              var flutterJSClass = JSClass.create(classDef);
              var flutterJSObject = JSObject.make(jsContext, flutterJSClass);
              jsContext.globalObject.setProperty('Text', flutterJSObject.toValue(),
                  JSPropertyAttributes.kJSPropertyAttributeDontDelete);
              final data = jsContext.evaluate("""
              [new Text('测试1'), new Text('测试2'), new Text('测试3')]
            """);
              final list = jsValueToList(data).map((e) => e.toObject().getProperty('text').string);
              print(list);
             // I/flutter ( 8752): (测试3, 测试3, 测试3)
            },
          )),
    );
  }
}

可以绑定Dart类吗?JSClassDefinetion

    final define = JSClassDefinition(
      className: 'DartTest',
      staticFunctions: [],
    );
    final jsobject = JSObject.make(jsContext, JSClass.create(define));

    jsContext.globalObject.setProperty(
      name,
      jsobject.toValue(),
      JSPropertyAttributes.kJSPropertyAttributeNone,
    );

只知道用这种方式来绑定静态方法,有方法可以绑定一个实例对象吗?可以在js端直接通过实例对象的名称来调用实例的方法。

谢谢

Error: Property 'count' cannot be accessed on 'JSValuePointer?' because it is potentially null.

I have following error after migrate to null safety .

lib/js/js_engine.dart:71:32: Error: Property 'count' cannot be accessed on 'JSValuePointer?' because it is potentially null.
 - 'JSValuePointer' is from 'package:myApp/js/js_core_mock.dart' ('lib/js/js_core_mock.dart').
Try accessing using ?. instead.
      if (jsContext!.exception.count > 0) {
                               ^^^^^
lib/js/js_engine.dart:71:38: Error: Operator '>' cannot be called on 'int?' because it is potentially null.
      if (jsContext!.exception.count > 0) {
                                     ^
lib/js/js_engine.dart:72:50: Error: Property 'count' cannot be accessed on 'JSValuePointer?' because it is potentially null.
 - 'JSValuePointer' is from 'package:myApp/js/js_core_mock.dart' ('lib/js/js_core_mock.dart').
Try accessing using ?. instead.
        for (int i = 0; i < jsContext!.exception.count; i++)

require这类要加载第三方的函数要这么做

本地js种使用到了require 自己本地通过setProperty的方式 的确让require在执行的时候 回调了回来
但是自己接管了require以后 就等于自身默认不在支持require语法

 var jsAlertFunction =
        JSObject.makeFunctionWithCallback(_jsContext, 'require', Pointer.fromFunction(require));
    _jsContext.globalObject.setProperty('require', jsAlertFunction.toValue(),
        JSPropertyAttributes.kJSPropertyAttributeNone);

比如这种语法
image

就会提示报错

我现在的问题 就是 如何能让jscore自身就支持require语法 并且可以自己去找指定文件读取

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.