From 874fb2cbc90c3a3861be3e6c74fd4061b70d54c2 Mon Sep 17 00:00:00 2001 From: Wayne Bloss Date: Sun, 4 Mar 2012 21:26:06 -0500 Subject: [PATCH] Added IActiveScriptProperty usage in a FAILED attempt to get EcmaScript 5.1 functionality from the Chakra JScript engine. Looks like we have to use a shim to get the functionality. --- .../Scripting/ActiveScript/Constants.cs | 16 ++++++++++++ .../Scripting/ActiveScript/Interfaces.cs | 9 +++++++ win/gel.exe/Scripting/JScript/JsEngine.cs | 13 ++++++++++ win/gel.exe/gel.js | 24 ++++++++++++++++++ win/gel.exe/shims.js | 25 ++++++++++++------- 5 files changed, 78 insertions(+), 9 deletions(-) diff --git a/win/gel.exe/Scripting/ActiveScript/Constants.cs b/win/gel.exe/Scripting/ActiveScript/Constants.cs index b502f20..8eb098c 100644 --- a/win/gel.exe/Scripting/ActiveScript/Constants.cs +++ b/win/gel.exe/Scripting/ActiveScript/Constants.cs @@ -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 { diff --git a/win/gel.exe/Scripting/ActiveScript/Interfaces.cs b/win/gel.exe/Scripting/ActiveScript/Interfaces.cs index 6944d4d..d1f938c 100644 --- a/win/gel.exe/Scripting/ActiveScript/Interfaces.cs +++ b/win/gel.exe/Scripting/ActiveScript/Interfaces.cs @@ -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); + } } diff --git a/win/gel.exe/Scripting/JScript/JsEngine.cs b/win/gel.exe/Scripting/JScript/JsEngine.cs index 2743038..84807d1 100644 --- a/win/gel.exe/Scripting/JScript/JsEngine.cs +++ b/win/gel.exe/Scripting/JScript/JsEngine.cs @@ -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; diff --git a/win/gel.exe/gel.js b/win/gel.exe/gel.js index 274f6e9..72f5564 100644 --- a/win/gel.exe/gel.js +++ b/win/gel.exe/gel.js @@ -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!!!!!!!!!!!!!!!!!!'); }); diff --git a/win/gel.exe/shims.js b/win/gel.exe/shims.js index e1bfcec..f0af58f 100644 --- a/win/gel.exe/shims.js +++ b/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]; - } -}; \ No newline at end of file +if (typeof {}.__proto__ == 'undefined') { + Object.prototype.__proto__ = function(source) { + for (var member in source) { + this[member] = source[member]; + } + }; +} \ No newline at end of file