js4vb vtComObjAuthor: Dave Date: 12.26.25 - 9:01am So in the js4vb js engine, everything is held as a CValue class instance with different types. Its like the script engine version of a variant. This includes numbers, strings, js functions, js objects, and COM object holders. different types can have properties assigned to them. Like a JS object can have fields of other types including functions. So normal convention would be that COM object types, forward all of their calls to the COM subsystem and do not have any JS properties or functions associated with them. But! thats just a convention, not an actual design requirement. In fact! with very few tweaks of the assumptions of the engine, we can start attaching js functions and properties to a COM object! This sounds crazy like adding functions to a vtable and extending a binary COM object is usually a dark art..but in our scenario, its actually just a parlor trick! This also allows us to override COM methods in JS, because we control the calling engine. Simply look for JS methods by name first, effectivly an override without changing the ground truth of the binary COM object. And if you want to still be able to call the original COM method thats overridden? Simple convention actually. Add an underscore to the method name. The COM call engine will see the underscore. If a JS method override exists with the base name, then we just strip the underscore and call the COM version not the JS version. Its actually super simple and took very little code to implement all of this! You see, there is no spoon... Adding COM helper methods can be done from the vb6 host side, or the JS side. Controlling your own javascript engine is a very satisfying experience. heres the commit if your interested. //vb6 intrep.AddCOMObject "form", Me intrep.AttachCOMHelper "form", "taco", "function(cmd){print('its tuesday ' + cmd + '!');}" //js var wsh = new ActiveXObject("WScript.Shell"); // Add a JS helper that uses the actual COM method wsh.safeExpandEnv = function(varName) { var result = this.ExpandEnvironmentStrings("%" + varName + "%"); if (result === "%" + varName + "%") { return "(undefined)"; // Variable doesn't exist } return result; }; console.log(wsh.safeExpandEnv("PATH")); // Returns expanded path or "(undefined)" form.taco('dude') wsh.Run = function(cmd) { console.log("[LOG] " + cmd); return this._Run(cmd, 1, true); // Calls original COM Run }; wsh.Run("C:WindowsSysWOW64 otepad.exe") In other news i started experimenting with sinking events for various controls just in case. Bad news through, we cant wire it up to intrisic vb form controls, only ocx and vb classes. Command buttons etc use vtables not idisp which we could hook but I wouldnt. A form engine with event handling would be pretty sweet to add to teh js engine! Comments: (1)On 01.17.26 - 4:32pm Dave wrote:
|
About Me More Blogs Main Site |
|