GithubHelp home page GithubHelp logo

Comments (3)

svaarala avatar svaarala commented on June 9, 2024

There seem to be multiple issues related to recent Emscripten changes.

First, Duktape does not currently support typed arrays (ArrayBuffer, UInt8Array etc) and it seems that Emscripten now requires them by default. Setting EMCC_FAST_COMPILER=0 in the env is needed to avoid this issue.

Then there is another issue with the following regexp in Emscripten generated output:

var sourceRegex = /^function\s\(([^)]*)\)\s*{\s*([^*]*?)[\s;]*(?:return\s*(.*?)[;\s]*)?}$/;

The brace characters ('{' and '}') are not escaped as required. This can be fixed manually (I'll submit a pull request for Emscripten for this).

After fixing this one gets:

$ ./duk /tmp/duk-emcc-test.js
TypeError: invalid base reference for property read
  duk_hobject_props.c:1938
  parseJSFunc /tmp/duk-emcc-test.js:653
  anon /tmp/duk-emcc-test.js:661
  global /tmp/duk-emcc-test.js:714 preventsyield

This is caused by the generated code trying to parse the toString() output of a function, e.g.:

function empty() {/* source code */}

The (fixed) regexp does not match this (which seems incorrect) but does match e.g.:

function () {}

The E5 spec only requires that function toString() output be in valid syntax (E5 Section 15.3.4.2):

An implementation-dependent representation of the function is returned. This representation
has the syntax of a FunctionDeclaration. Note in particular that the use and placement of white
space, line terminators, and semicolons within the representation String is implementation-
dependent.

The offending function is:

var sourceRegex = /^function\s\(([^)]*)\)\s*{\s*([^*]*?)[\s;]*(?:return\s*(.*?)[;\s]*)?}$/;
function parseJSFunc(jsfunc) {
  // Match the body and the return value of a javascript function source
  var parsed = jsfunc.toString().match(sourceRegex).slice(1);
  return {arguments : parsed[0], body : parsed[1], returnValue: parsed[2]}
}

Just as a quick fix, this makes the hello world test work again:

var sourceRegex = /^function\s\(([^)]*)\)\s*\{\s*([^*]*?)[\s;]*(?:return\s*(.*?)[;\s]*)?\}$/;
function parseJSFunc(jsfunc) {
  // Match the body and the return value of a javascript function source
  var parsed = jsfunc.toString().match(sourceRegex);
  if (!parsed) { return {}; }
  parsed = parsed.slice(1);
  return {arguments : parsed[0], body : parsed[1], returnValue: parsed[2]}
}

from duktape.

svaarala avatar svaarala commented on June 9, 2024

The above comment reactivates fix_emscripten.py and adds the necessary regexp fixes to Emscripten output to allow Hello World test to work again. I'll submit fixes to Emscripten soon.

from duktape.

svaarala avatar svaarala commented on June 9, 2024

The util/fix_emscripten.py now fixes a few more issues, all related to Emscripten using a few regexps outside the strict E5 syntax. There's a Ditz issue for tracking that they're submitted to Emscripten closer to 1.0, I'll close this now.

from duktape.

Related Issues (20)

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.