godmodelabs / ejecta-v8

A port of @phoboslabs EjectaJS which uses v8 instead of JavaScriptCore.
http://godmodelabs.github.io/ejecta-v8/
84 stars 16 forks source link

"canvas is not a constructor" #12

Open lakeinchina opened 6 years ago

lakeinchina commented 6 years ago

I compile ejecta-v8 as a module of ejecta-v8-sample.when i 'run in Ejecta-v8 View' , it crash. plasma.js:

    var canvas = require('canvas');
    console.log("canvasA="+canvas);
    var c = new canvas(view);

ag.boersego.bgjs.sample I/BGJSV8Engine-jni: viewCreated called [object Arguments] ag.boersego.bgjs.sample I/BGJSV8Engine-jni: canvasA=[object HTMLCanvasElement]

beginning of crash ag.boersego.bgjs.sample E/AndroidRuntime: FATAL EXCEPTION: Thread-4296 Process: ag.boersego.bgjs.sample, PID: 23679 ag.boersego.bgjs.V8Exception: An exception was thrown in JavaScript at ag.boersego.bgjs.JNIV8Function._callAsV8Function(Native Method) at ag.boersego.bgjs.JNIV8Function.callAsV8Function(JNIV8Function.java:22) at ag.boersego.bgjs.sample.DemoEjectaFragment.initializeV8(DemoEjectaFragment.java:76) at ag.boersego.bgjs.sample.DemoEjectaFragment.access$200(DemoEjectaFragment.java:24) at ag.boersego.bgjs.sample.DemoEjectaFragment$1$1.onGLCreated(DemoEjectaFragment.java:97) at ag.boersego.bgjs.V8TextureView$RenderThread.run(V8TextureView.java:743) Caused by: ag.boersego.bgjs.V8JSException: [TypeError] canvas is not a constructor at global.startPlasma(js/plasma.js:106)

any help?

lakeinchina commented 6 years ago

well,canvas is a function,so I replaced

var c = new canvas(view);

with

var c = canvas(view);

And it works,but why?

unverbraucht commented 6 years ago

These are two different ways of calling constructors in v8 native-backed functions. I'll look into it, thanks.