Author Topic: JS60 engine implementation documentation.  (Read 251 times)

timoc

  • EA User
  • **
  • Posts: 104
  • Karma: +6/-0
    • View Profile
JS60 engine implementation documentation.
« on: June 19, 2019, 09:47:18 pm »
There is an assumption that the Javascript engine embedded in the EA is in line with the ES5 (ES6?) standard supported by the Mozilla Spidermonkey v60. This is the pre-requisite to allow me to use open/off the shelf Javascript to supplement my EA automation.

I have yet to find any technical documentation, except an assertion that it is based on the gecko v60 JS runtime (standalone available here windows/linux),

I have recently started testing this assumption, or rather exploring the abilities of the JS engine from the inside. My approach so far is reminiscent of how you got things working in the browser wars, where you try and get an idea about the properties from inside and outside of the Javascript engine context. You do this by using JS reflection techniques to dump the properties from global scope in the running context, and a debugger on the running context.

Before i go to far and re-invent the wheel though, is there documentation on the JS engine implementation?
More specifically:
- what is the object that defines the global scope. there is no globalThis defined, but the root 'this' (see script below) is not behaving as a typical global scope object would.
- how do i tell i am in a Javascript and not JScript context?
- how do i tell which of the pre-defined contexts the script is running in?
- where is the 'var <blah> as' operator documented.
Investigation using the script debugger on the script below, shows that these 'as' objects are already available to the script execution context.
Code: [Select]
function getGlobal2() {
  return (function(global) {
    return global;
  })(new Function('return this;')());
}

var temp=getGlobal2();
Session.Output("----- globaldump");
// rightclick to insert debugger breakpoint on line below
Session.Output(Object.getOwnPropertyNames(temp));

The implication being that there can only be one instance of a given 'as' defined object - meaning it is always a global object?. Does it only work in var statements? Can i scope these with let?
- So does it matter which execution context a script it is running in?

Pointers and experiences also appreciated.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 9469
  • Karma: +266/-27
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: JS60 engine implementation documentation.
« Reply #1 on: June 19, 2019, 10:56:53 pm »
I don't have any experience with Javascript, but a lot with VBScript, and there are a few questions that I might be able to answer.

The var <bar> as EA.<foo> is nothing more then a tool for EA to provide intellisense in the the script editor.
I'm pretty sure EA strips these "as EA.<foo>" statements before it provides the script to the scripting engine. If it would not that would result in syntax errors.
They are not needed by script at all, and not used by the whatsoever.

There are (at least) two global objects that are present in the context of every script:
- Repository -> EA.Repository object representing the model
- Session -> to do stuff like Session.Output

I don't think your assumptions about the "as" objects are valid.

The third "quirk" are the !INC statements.
Those will simply copy code of the included script at the place of the !INC statement.

Geert

Sunshine

  • EA User
  • **
  • Posts: 853
  • Karma: +66/-4
  • Its the results that count
    • View Profile
Re: JS60 engine implementation documentation.
« Reply #2 on: June 20, 2019, 06:07:58 am »
Try using V15 as it uses Mozilla Spidermonkey 63. Earlier versions of Sparx use a very much older version.
V15 is still in beta but functional and will more than likely be released soon.
Happy to help
:)

timoc

  • EA User
  • **
  • Posts: 104
  • Karma: +6/-0
    • View Profile
Try using V15 as it uses Mozilla Spidermonkey 63. Earlier versions of Sparx use a very much older version.
V15 is still in beta but functional and will more than likely be released soon.
Hi Sunshine,

I have standardized my testing and focus on Spidermonkey v60, specifically because it is the version currently supported by 'off the shelf' cross platform tooling.
On Linux i only need to use
Code: [Select]
dnf install mozjs60-devel and i have an equivalent javascript development and testing environment, with native tools etc.

I was aware that 15 has Spidermonkey v63, so i have been using it for my tests so far. I will make that clear from now on  :)