Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using jsdom on Trireme (Windows) #80

Closed
chris-h-sg opened this issue Aug 13, 2014 · 5 comments
Closed

Using jsdom on Trireme (Windows) #80

chris-h-sg opened this issue Aug 13, 2014 · 5 comments

Comments

@chris-h-sg
Copy link

Is it possible to run jsdom on Trireme?
On Windows, I have jsdom installed and working in my regular NodeJS installation. However, when I'm trying to run

require("jsdom");

in Trireme, I'm getting an exception saying ReferenceError: "MZ" is not defined.

Ultimately, this is coming from jsdom trying to load contextify.node, which is a binary file and happens to start with the characters MZ.

Stack trace:

"MZ" is not defined.
    at C:\Users\Chris\node_modules\jsdom\node_modules\contextify\build\Release\contextify.node:1
    at module.js:456
    at module.js:474
    at module.js:356
    at module.js:312
    at module.js:364
    at require (module.js:380)
    at bindings (C:\Users\Chris\node_modules\jsdom\node_modules\contextify\node_modules\bindings\bindings.js:76)
    [...]

Is there a way to do this with Trireme?

@gbrail
Copy link
Contributor

gbrail commented Aug 13, 2014

Yes, that looks like an instance of the general problem that Trireme can't
run native C/C++ code, and contextify seems to be one of those modules that
uses native code to extend what Node can do by jacking in to the lower
level features of V8.

When these things come up, we really have three issues:

  1. See if the dependency *really *needs the native module and can work
    around it
  2. Implement the native functionality in Trireme (the "trireme-utils"
    module has a few of these already)
  3. Find another module to use

One example of this is an LDAP module someone was using that depended on
"buffertools":

https://www.npmjs.org/package/buffertools

which uses native code to extend what the Buffer class can do.

In this case the author of the LDAP module had reworked the code so that it
didn't depend on buffertools at all.

It'd be interesting to know where "jsdom" uses contexify and why -- do you
have the full stack trace? I wasn't able to find it in a quick scan of the
main code.

On Tue, Aug 12, 2014 at 11:33 PM, Chris [email protected] wrote:

Is it possible to run jsdom on Trireme?
On Windows, I have jsdom installed and working in my regular NodeJS
installation. However, when I'm trying to run

require("jsdom");

in Trireme, I'm getting an exception saying ReferenceError: "MZ" is not
defined.

Ultimately, this is coming from jsdom trying to load contextify.node,
which is a binary file and happens to start with the characters MZ.

Stack trace:

"MZ" is not defined.
at C:\Users\Chris\node_modules\jsdom\node_modules\contextify\build\Release\contextify.node:1
at module.js:456
at module.js:474
at module.js:356
at module.js:312
at module.js:364
at require (module.js:380)
at bindings (C:\Users\Chris\node_modules\jsdom\node_modules\contextify\node_modules\bindings\bindings.js:76)
[...]

Is there a way to do this with Trireme?


Reply to this email directly or view it on GitHub
#80.

greg brail | apigee https://apigee.com/ | twitter @gbrail
http://twitter.com/gbrail

https://pages.apigee.com/i-love-apis-2014.html?utm_source=sig&utm_medium=email

@chris-h-sg
Copy link
Author

Thanks for the quick answer!

I don't have a stack trace of jsdom actually using contextify - the error occurs when it's trying to require it while loading.
It looks like contextify is pretty essential to jsdom. In particular, it seems to provide support for setTimeout and other callbacks. There's a lightweight variation without the dependency, but it has to drop several fairly central features to get there.

Incidentally, avatar-js doesn't seem to have a solution either.

Contextify itself seems to be pretty small, with some 300 lines of C++ code and 50 lines of JavaScript.

To your suggestions:

  1. Apparently it's needed. The jsdom people and users don't seem happy about the dependency either since it makes it harder to install on Windows, but it's been there for years without an alternative.
  2. Does this look like something that could be implemented natively?
  3. For a full DOM implementation on Node, there are currently no alternatives to jsdom.

If there is no other way to deal with this, what's your point of view on a native implementation?

@gbrail
Copy link
Contributor

gbrail commented Oct 15, 2014

I implemented a way to load "native modules" as JAR files, and wrote one for "contextify." With that, contextify and its tests pass.

I also ran many of the jsdom tests and many of them failed, but not due to missing native code. But I think that with the next release this is going to be as fixed as it can be.

@alex88
Copy link

alex88 commented Sep 7, 2015

@gbrail what's the current way to be able to use contextify?

@gbrail
Copy link
Contributor

gbrail commented Sep 8, 2015

It should "just work." The module is written in JS and depends on a native
module that is normally compiled using NPM from the C++ source. Trireme has
a Java implementation of that native module in the "trireme-util" module.
So, I'd appreciate it if someone could try the latest version, and then we
can look and see if something needs to be fixed.

On Mon, Sep 7, 2015 at 6:21 AM, Alessandro Tagliapietra <
[email protected]> wrote:

@gbrail https://github.com/gbrail what's the current way to be able to
use contextify?


Reply to this email directly or view it on GitHub
#80 (comment).

Greg Brail | apigee https://apigee.com/ | twitter @gbrail
http://twitter.com/gbrail @apigee https://twitter.com/apigee
http://iloveapis.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants