envjs / env-js Goto Github PK
View Code? Open in Web Editor NEWThis project forked from thatcher/env-js
A pure-JavaScript browser environment.
Home Page: http://www.envjs.com/
This project forked from thatcher/env-js
A pure-JavaScript browser environment.
Home Page: http://www.envjs.com/
currently the require definition is followed directly by use of require to load envjs. this prevents the user from being able to add paths to the require directive for where they want envjs to load from.
The implementation of HTMLAnchorTag
doesn't support URLUtils.pathname
.
I discovered this issue while attempting to utilize sbt-jasmine-plugin to unit test an angular.js application. I have tracked down this issue with env.js as the cause of this issue I reported. I also opened this Stackoverflow question.
I intend to implement it per this documentation.
The method insertBefore
in dom.js starts with the following debug statement:
log.debug('insert %s Before %s', newChild.nodeName, refChild.nodeName);
But results in a TypeError: Cannot read property 'nodeName' of null when the refChild (or newChild is undefined). This can be fixed as follows:
log.debug('insert %s Before %s', newChild && newChild.nodeName, refChild && refChild.nodeName);
See commit orslumen@c22faaf
But would it not be better (performance wise) to comment out all log statements, or to add something like if (Log.level <= debug) { log.debug(...) }
to all debug statements?
I have no idea how this happened but it obviously breaks the rubyracer platform. See this mailing list thread for more info: https://github.com/inbox/4182005
When the 'href' attribute of a HTMLAnchorElement is set to '#' or 'javascript:void(0);', a click should not lead to a location change.
A workaround can be found in orslumen@80c79e3
one test is commented out in specs/html/spec.js but runs just fine
Project code here:
I get the feeling this project is long since abandoned, but I'll leave this here for what it's worth. It was a great project, BTW!
Env.js 1.2 doesn't support a.hash. That is, if you create an anchor tag, with an href, and then try to look it up via a.hash, it returns undefined. This code fixes that (albeit crudely):
HTMLElement.prototype.setAttribute = function(name, value) {
//console.log("CSS set attribute: " + name + ", " + value);
origSetAttribute.apply(this, arguments);
if (name === "style") {
updateCss2Props(this, value);
}
// Add support for 'HTMLAnchorTag.hash'
if (this.tagName === "A" && name === "href" && value.indexOf( "#" ) !== -1 ) {
this.hash = value.substring( value.indexOf( "#" ));
}
}
When a different page is loaded, the window.unload event is not emitted.
For now I have added the following code at the top of Envjs.exchangeHTMLDocument in core.js:
try {
if (doc === window.document) {
event = doc.createEvent('HTMLEvents');
event.initEvent('unload', false, false);
window.dispatchEvent( event, false );
}
} catch (eee) {
log.debug('window unload event failed %s', eee);
//swallow
}
I am note sure though whether or not this code is in the right location... see orslumen@2c2027e
Some fixes were needed to get jQuery 1.5.1 working with EnvJs in Ruby Racer:
i) The jQuery.clone
method uses an expando attribute that is removed in jQeury.cloneFixAttributes
. But that attribute may not be present on the current node. If doc.implementation.errorChecking === false
it should fail silently, see NamedNodeMap#removeNamedItem(NS)
.
ii) jQuery directly retrieves and sets the value attribute on the nodes, but (at least in Ruby Racer) the NamedNodeMap does not accept a call to value=. To fix this, explicit getter and setters are added, see NamedNodeMap#get/set value
iii) jQeury.cloneFixAttributes
makes use of Element.clearAttributes
and Element.mergeAttributes
. Both methods were not defined yet.
The code changes I used to get jQuery 1.5.1 working can be found in orslumen@c3e702c
When parsing a Document Fragment, the appendChild method calls Array.prototype.push.apply(nodelist, newChild.childNodes.toArray() );
But as NodeList.toArray()
returns self, you will receive Exception TypeError: Function.prototype.apply: Arguments list has wrong type.
I got around this issue by putting back the original toArray()
method:
toArray: function () {
var children = [];
for ( var i=0; i < this.length; i++) {
children.push (this[i]);
}
return children;
},
See commit orslumen@bb3c8db
In xhr.js line 453 refers to responseHeader
, that should be responseHeaders
if(this.responseHeaders.hasOwnProperty(header)){
see orslumen@44fb38d
Note that when working with jQuery 1.5.1 all XHR requests will fail on this, as jQuery uses the standard XMLHttpRequest that is defined in xhr.js
One of my jQuery plugins uses the $.wrap()
function. After that method is called, the getElementsByTagName
function returns incorrect results. It completely ignores the new element and moves the wrapped element to the end of the list.
To reproduce (without jQuery):
<html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'>
<head/>
<body>
#container
#before
#to_be_wrapped
#after
<script type="text/javascript">
//<![CDATA[
// Print the current state to the console, this is OK
var container = document.getElementById('container');
console.log('\r\nBefore:\r\n'+container.innerHTML);
var all = container.getElementsByTagName('*'); var ids = ''; for(var i=0; i < all.length; i++) { ids = ids + (String.isBlank(ids) ? '' : ', ') + all[i].getAttribute('ID'); } console.log('getElementsByTagName("*") returns%selements:%s', all.length, ids);
// Wrap the #to_be_wrapped node in a new #wrapper node
var wrapper = document.createElement('div');
wrapper.id = "wrapper";
var to_be_wrapped = document.getElementById('to_be_wrapped');
container.insertBefore(wrapper, to_be_wrapped);
wrapper.appendChild(to_be_wrapped);
// Print the results of the incorrect state of getElementsByTagName
console.log('\r\nAfter:\r\n'+container.innerHTML);
all = container.getElementsByTagName('*'); ids = ''; for(var i=0; i < all.length; i++) { ids = ids + (String.isBlank(ids) ? '' : ', ') + all[i].getAttribute('ID'); } console.log('getElementsByTagName("*") returns%selements:%s', all.length, ids);
// Show that childNodes still reflects the correct state
all = container.childNodes; ids = ''; var id_count = 0; for(var i=0; i < all.length; i++) { if (all[i].nodeType == Node.ELEMENT_NODE) { id_count++; ids = ids + (String.isBlank(ids) ? '' : ', ') + all[i].getAttribute('ID'); } } console.log('childNodes returns%selements:%s', id_count, ids);
//]]>
</script>
</body>
</html>
This produces the following results:
Before:
<div id="before"/>
<div id="to_be_wrapped"/>
<div id="after"/>
getElementsByTagName("*") returns 3 elements: before, to_be_wrapped, after
After:
<div id="before"/>
<div id="wrapper"><div id="to_be_wrapped"/></div>
<div id="after"/>
getElementsByTagName("*") returns 3 elements: before, after, to_be_wrapped
childNodes returns 3 elements: before, wrapper, after
As you can see the innerHTML is correct, but the container.getElementsByTagName("*")
is missing the #wrapper div and has incorrectly moved the #to_be_wrapped div to the end.
Fortunately the childNodes
property does contain the correct state, so as a workaround I switched back to the old recursive implementation of getElementsByTagName using childNodes, which seems to work fine for the moment.
I’m trying JavaScript Development Tool and it comes with Rhino as debugging tool. It is very nice.
I was able to make envjs-1.2.13 working. Now, switching to the 1.3 pre03. Hitting issue on path setting..
Under envjs/rhino.js, at the end it calls require to load in additional modules.
require('envjs/platform/rhino');
require('envjs/window');
But inside require, it relies on the “user.dir” to search for file and it fail for my case since, user.dir will return the directory where Eclipse is started from.
var currentPath = java.lang.System.getProperty('user.dir');
Should it goes with the way to have an envjsConfig object with baseUrl property set prior to load Envjs?
Then, internally, use the object to load file accordingly.
I did a simple hack & get all the files loaded but I’m still seeing weird things (newbie to java & javascript)
Somewhere the file path are messed up...
org.mozilla.javascript.WrappedException: Wrapped java.net.URISyntaxException: Illegal character in path at index 10: file://C/:\Eclipse-indigo/C:\workspace\client\scripts\example\simple.js (file:/C:/workspace/client/scripts/envjs/platform/rhino.js#251)
at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1773)
at org.mozilla.javascript.MemberBox.newInstance(MemberBox.java:202)
at org.mozilla.javascript.NativeJavaClass.constructSpecific(NativeJavaClass.java:281)
at org.mozilla.javascript.NativeJavaClass.construct(NativeJavaClass.java:200)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3377)
at script(file:/C:/workspace/client/scripts/envjs/platform/rhino.js:251)
at script(file:/C:/workspace/client/scripts/envjs/platform/core.js:1021)
at script(file:/C:/workspace/client/scripts/envjs/platform/core.js:2403)
at script(file:/C:/workspace/client/scripts/envjs/platform/core.js:1007)
at script(file:/C:/workspace/client/scripts/envjs/platform/core.js:943)
at script(file:/C:/workspace/client/scripts/envjs/window.js:855)
at script(file:/C:/workspace/client/scripts/envjs/window.js:34)
at script.require(/C:/workspace/client/scripts/envjs/rhino.js:85)
at script(/C:/workspace/client/scripts/envjs/rhino.js:108)
at script(/C:/workspace/client/scripts/envjs/rhino.js:105)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2487)
at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:178)
at org.mozilla.javascript.tools.shell.Main.evaluateScript(Main.java:564)
at org.mozilla.javascript.tools.shell.Main.processFileSecure(Main.java:486)
at org.mozilla.javascript.tools.shell.Main.processFile(Main.java:452)
at org.mozilla.javascript.tools.shell.Global.load(Global.java:244)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:161)
at org.mozilla.javascript.FunctionObject.call(FunctionObject.java:413)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3330)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2487)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:398)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065)
at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
at org.mozilla.javascript.tools.shell.Main.evaluateScript(Main.java:564)
at org.mozilla.javascript.tools.shell.Main.processFileSecure(Main.java:486)
at org.mozilla.javascript.tools.shell.Main.processFile(Main.java:452)
at org.eclipse.wst.jsdt.debug.rhino.debugger.shell.DebugMain$Evaluator.run(DebugMain.java:89)
at org.mozilla.javascript.Context.call(Context.java:515)
at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:507)
at org.eclipse.wst.jsdt.debug.rhino.debugger.shell.DebugMain.main(DebugMain.java:218)
Caused by: java.net.URISyntaxException: Illegal character in path at index 10: file://C/:\Eclipse-indigo/C:\workspace\client\scripts\example\simple.js
at java.net.URI$Parser.fail(Unknown Source)
at java.net.URI$Parser.checkChars(Unknown Source)
at java.net.URI$Parser.parseHierarchical(Unknown Source)
at java.net.URI$Parser.parse(Unknown Source)
at java.net.URI.(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.mozilla.javascript.MemberBox.newInstance(MemberBox.java:194)
... 28 more
If the document location is set to a similar URL, do not reload the page.
To fix this I added the following line of code, but I can imagine the URL comparison can be optimized (e.g. by removing blanks at the end of the url):
set href(url) {
if (url === $url || url+'#' === $url || url === $url+'#') { return; }
...
}
See orslumen@a72ff2e
http://groups.google.com/group/envjs/browse_thread/thread/4d9bd737f68cf78b
This requires allowing the Envjs.eventLoop to run in 'an indefinite loop' which means running an exact callstack n-times before providing an Envjs.unresponsive hook.
Am I on the right track here?
Thatcher
When a different page is loaded, the timers defined in the old page are still active.
For now I have added the following code to Envjs.exchangeHTMLDocument in core.js:
if (doc === window.document) {
Envjs.timers.length = 0;
}
But that may be too crude a method when there are multiple windows involved.
Well, this is more of an enhancement request than a bug.
I am running my integration tests asynchronously. Next to that I make sure that (most) calls to setTimeout use a timeout of 0 (zero) during the integration tests, to perform well.
But timer.js by default adds all timers and intervals to the queue, regardless of the timeout value.
I would like setTimeout to synchronously call the given function when the timeout is set to zero, see e.g. orslumen@fe499c2
When I have a clickable div on an html page like:
And I send a mouse-click event to the #clickme div, nothing happens.
Example: http://jsfiddle.net/EHezK/
currently envjs treats all html pages as utf-8, we should be scanning for a meta tag which declares character encoding
I'm currently in the process of porting env.js to Nashorn. While trying to run jQuery I discovered that the toString method in window.js (https://github.com/envjs/env-js/blob/master/envjs/window.js#L749) actually causes all objects to return '[Window]' when their toString method is called.
Chrome:
>toString()
"[object Window]"
>toString.call("test")
"[object String]"
>var a = {}
undefined
>a.toString()
"[object Object]"
Nashorn + env:
console.log(toString());
>>[Window]
console.log(toString.call("test"));
>>[Window]
var a = {};
console.log(a.toString());
>>[Window]
jQuery is unable to make ajax requests because the toString method is used when registering the transports (https://github.com/jquery/jquery/blob/master/src/ajax.js#L61). Since the toString method is broken, jQuery's "typeof" method will default to calling the transport functions objects which causes the "isFunction" check to fail, preventing any transports from being registered.
Posting form-data using Ruby Racer did not work for me.
I got it working by passing the form-data as the data argument to the HTTPConnection.go
method.
Next to that my Rails App was not receiving some HTTP_xxx request headers and the response status code was not parsed correctly.
The codefixes that I used can be found in commit
orslumen@b294e11
I am not sure though whether or not this fix would work for everyone.
Hello,
I try to write a little script with Ruby on a Linux Fedora 64 bits box.
I am using the gem 'therubyracer-heroku-0.8.1' for the V8 machine because the gem 'therubyracer' fails to compile on 64 bits with gcc RedHat 4.5.1.
So, in my script, i load the 'envjs/rubyracer.rb' and it success with Ruby 1.8.7 but fails with Ruby 1.9.2 for two reasons :
-1) 'configure_context' method fails for compatibility reason on 'eval'. Just add to_s method to the parameter of 'eval'.
-2) Exception raised with that stack :
👎 Uncaught TypeError: Cannot convert object to primitive value
ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/portal.rb:118:in block in v8': undefined method
SetHiddenValue' for #V8::C::Value:0x0000000154fa28 (NoMethodError)
ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/portal.rb:117:in tap' ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/portal.rb:117:in
v8'
ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/portal.rb:111:in block (2 levels) in v8' ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/portal.rb:110:in
each'
ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/portal.rb:110:in block in v8' ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/portal.rb:109:in
tap'
ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/portal.rb:109:in v8' ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/object.rb:19:in
block (2 levels) in []='
ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/portal.rb:75:in block in open' ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/context.rb:79:in
enter'
ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/portal.rb:74:in open' ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/object.rb:18:in
block in []='
ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/object.rb:17:in tap' ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/object.rb:17:in
[]='
ruby-192p136/lib/ruby/gems/1.9.1/gems/therubyracer-heroku-0.8.1.pre3/lib/v8/context.rb:58:in []=' envjs/rubyracer.rb:47:in
configure_context'
from ./go.sh:7:in load' from ./go.sh:7:in
Any idea ?
Regards.
When selectedIndex is requested for the first time, I think it is best to select the first item in the dropdown if nothing was selected and an option is available.
I did not verify that this is according to specs, but at least FF, IE, Safari and Chrome will never return null in case an option is available.
One way to fix this can be found in orslumen@18d271d
But it is probably more correct to select the first option once the HTML is parsed and no options have been marked as selected yet.
In CSS2Properties of css.js , the setProperty method stores updated CSS properties in the styleIndex variable, but that object is shared between multiple (all?) nodes.
So when a CSS property is dynamically updated in one node, it also changes in all other nodes.
One way to fix is is by storing all changed properties in a separate variable, see orslumen@aa0318d
In jQuery 1.6.4, the Ajax Transport checks if the request is "crossDomain" and, if so, requires jQuery.support.cors to be true:
if ( !s.crossDomain || jQuery.support.cors ) {
CORS support checks for the existence of the 'withCredentials' property (default boolean false), which is not present in Envjs.
I added it in this commit: vanm@2f485c0
Since most requests in our test suite are classified as "crossDomain" by jQuery, this is required to get $.ajax requests working properly.
window.location = 'http://www.zope.com';
envjs just exits...
I tried to use $.getJSON (with jQuery) to test some AJAX callbacks, but doesnt work.
a lot of use case require envjs at least make the request and honor cookies in response even if it doesnt load the image. See this thread,
http://stackoverflow.com/questions/5171765/google-analytics-in-java-with-rhino-and-envjs
and
http://groups.google.com/group/envjs/browse_thread/thread/25310a35347cb5a?hl=en
First of all, thank you for the great work on envjs!
While upgrading our integration tests from envjs 0.3.7 to 1.3.pre1 I noticed that when insertCell
(html.js) is called with idx === numCells
an error is thrown, because node is null when passed to insertBefore
.
To fix this, the line this.insertBefore(cell, node);
needs to be placed 2 lines higher within the else block. So the new cell is either appended at the end of the row, or inserted before an existing cell.
Kind regards,
Orslumen
PS. If you prefer a pull request, pls let me know.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.