Navigation Menu

Skip to content

Commit

Permalink
Added IActiveScriptProperty usage in a FAILED attempt to get EcmaScri…
Browse files Browse the repository at this point in the history
…pt 5.1 functionality from the Chakra JScript engine.

Looks like we have to use a shim to get the functionality.
  • Loading branch information
waynebloss committed Mar 5, 2012
1 parent 0e9d54f commit 874fb2c
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 9 deletions.
16 changes: 16 additions & 0 deletions win/gel.exe/Scripting/ActiveScript/Constants.cs
Expand Up @@ -43,6 +43,22 @@ enum ScriptItem : uint
NoCode = 0x0400,
}

enum ScriptLangVer : int
{
SCRIPTLANGUAGEVERSION_DEFAULT = 0,
V5_7 = 1,
V5_8 = 2,
V9 = 3
}

enum ScriptProp : uint
{
INTEGERMODE = 0x00003000,
STRINGCOMPAREINSTANCE = 0x00003001,
ABBREVIATE_GLOBALNAME_RESOLUTION = 0x70000002,
INVOKEVERSIONING = 0x00004000,
}

[Flags]
enum ScriptText : uint
{
Expand Down
9 changes: 9 additions & 0 deletions win/gel.exe/Scripting/ActiveScript/Interfaces.cs
Expand Up @@ -218,4 +218,13 @@ interface IActiveScriptParse64
out object result,
out EXCEPINFO exceptionInfo);
}

[ComImport]
[Guid("4954E0D0-FBC7-11D1-8410-006008C3FBFC")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IActiveScriptProperty
{
void GetProperty(ScriptProp dwProperty, IntPtr pvarIndex, [Out] out object pvarValue);
void SetProperty(ScriptProp dwProperty, IntPtr pvarIndex, [In] ref object pvarValue);
}
}
13 changes: 13 additions & 0 deletions win/gel.exe/Scripting/JScript/JsEngine.cs
Expand Up @@ -26,9 +26,22 @@ public JsEngine()

public JsEngine(UnhandledExceptionEventHandler uexHandler)
{
//DocVersionString = "DOCTYPE html";

_engine = CreateNativeEngine();
_engine.SetScriptSite(this);

// Set properties.
var activeScriptProperty = (IActiveScriptProperty)_engine;

// Indicate that we are not combining multiple script engines.
//object value = true;
//activeScriptProperty.SetProperty(ScriptProp.ABBREVIATE_GLOBALNAME_RESOLUTION, IntPtr.Zero, ref value);

// Upgrade the version of the script engine to 5.8 (IE 8).
object value = (int)ScriptLangVer.V9;
activeScriptProperty.SetProperty(ScriptProp.INVOKEVERSIONING, IntPtr.Zero, ref value);

_parser = new ActiveScriptParser(_engine);
_parser.InitNew();
_uexHandler = uexHandler;
Expand Down
24 changes: 24 additions & 0 deletions win/gel.exe/gel.js
Expand Up @@ -21,6 +21,30 @@ var global;
startup.globalVariables();
startup.globalTimeouts();

console.log(engineVer());

console.log('Object.defineProperties: ' + typeof Object.defineProperties);

// Create a user-defined object.
// To instead use an existing DOM object, uncomment the line below.
var obj = {};
// var obj = window.document;

// Add a data property to the object.
// Object.defineProperty(obj, "newDataProperty", {
// value: 101,
// writable: true,
// enumerable: true,
// configurable: true
// });

// Set the property value.
obj.newDataProperty = 102;
console.log("Property value: " + obj.newDataProperty);

// Output:
// Property value: 102

process.on('exit', function() {
console.log('exiting!!!!!!!!!!!!!!!!!!');
});
Expand Down
25 changes: 16 additions & 9 deletions win/gel.exe/shims.js
@@ -1,11 +1,18 @@

Array.isArray = function(o) {
return (o instanceof Array) ||
function engineVer() {
return ScriptEngine() + '/' + [ScriptEngineMajorVersion(), ScriptEngineMinorVersion(), ScriptEngineBuildVersion()].join('.');
}

if (typeof Array.isArray == 'undefined') {
Array.isArray = function(o) {
return (o instanceof Array) ||
(Object.prototype.toString.apply(o) === '[object Array]');
};
};
}

Object.prototype.__proto__ = function(source) {
for (var member in source) {
this[member] = source[member];
}
};
if (typeof {}.__proto__ == 'undefined') {
Object.prototype.__proto__ = function(source) {
for (var member in source) {
this[member] = source[member];
}
};
}

0 comments on commit 874fb2c

Please sign in to comment.