1

Closed

register Global Object as window by default

description

This will make Jurassic more compatible to other JS Engines and make easier porting Javascript libraries to run on Jurassic.
Closed Feb 1, 2012 at 8:41 PM by paulbartrum
Adding "window" to the global namespace without also implementing the rest of the DOM would be pretty worthless in my opinion. And as Alxandr states, the goal of this project is not to write a browser but to implement the ECMAScript standard in pure .NET. I am not averse to adding extensions that are not part of the spec, but they should be small, standalone and useful in a browserless environment (like web workers, for instance) and not large, complicated and intricately tied to a browser rendering engine (like the DOM).

comments

Alxandr wrote Feb 1, 2012 at 5:13 PM

This will break with the JavaScript standard while adding nothing in return. I believe it was stated somewhere on this page that Jurassic do not try to be a browser. To be compatible with most js web-frameworks out there, you'd need DOM0 to say the least, and that would be a hellova lot of work, and would possibly be a project that builds on jurassic, but not jurassic itself. Jurassic is inteded to be a pure JS-engine, and that's what it is.

cmcbf wrote Feb 1, 2012 at 6:45 PM

but some non browsers javascript engines have an striped window object as global object. and the scripts writed to these engines have window. See JSRENDER.JS (microsoft) for example.

cmcbf wrote Feb 1, 2012 at 9:06 PM

I dont want that you implement a DOM. I want that scripts made for server side environments (that dont have a DOM) also compile inside JURASSIC. In these enviroments window is an alias to GlobalObject.

See bellow an script made by Microsoft that work client side and server side but not work in Jurassic:


/*! JsRender v1.0pre - (jsrender.js version: does not require jQuery): http://github.com/BorisMoore/jsrender */
/*
  • Optimized version of jQuery Templates, fosr rendering to string, using 'codeless' markup.
    *
  • Copyright 2011, Boris Moore
  • Released under the MIT License.
    */
    window.JsViews || window.jQuery && jQuery.views || (function( window, undefined ) {
.... code ......

}
})( window );

To make this script work both on client side and server side i need to modify the last line from (window); to (this); but this make me to modify original source of script or register an window on ScriptEngine.

Also what is the default global scope name per spec in Javascript ? ("this" is not apropriate because "this" is correlate to context and not to global context).

paulbartrum wrote Feb 2, 2012 at 3:27 AM

I accept that mapping "window" to the global object is useful in this instance - but I don't believe that it would be generally useful.

As per the spec, there is no name for the global object - using "this" is the only way to get a reference to it (in JavaScript).

cmcbf wrote Feb 3, 2012 at 12:32 PM

And what about an option in ScriptEngine like engine.TreatGlobalObjectAsWindow = true/false ?

This will not break javascript compatibility with spec standard and make it possible Jurassic be compatible with de facto standard and run these scripts.

paulbartrum wrote Feb 4, 2012 at 12:52 AM

You don't need a property to do this, just use: engine.Global["window"] = engine.Global;