private static void Require(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); NSJSString rawUri = arguments.Length > 0 ? arguments[0] as NSJSString : null; if (rawUri == null || rawUri.DateType != NSJSDataType.kString) { arguments.SetReturnValue(false); } else { NSJSVirtualMachine machine = arguments.VirtualMachine; NSJSObject global = machine.Global; string path = rawUri.Value; string source; if (string.IsNullOrEmpty(path)) { arguments.SetReturnValue(false); } else { int index = path.IndexOf('#'); if (index > -1) { path = path.Substring(0, index); } index = path.IndexOf('?'); if (index > -1) { path = path.Substring(0, index); } do { bool success = false; if (!FileAuxiliary.TryReadAllText(path, out source)) { if (!FileAuxiliary.TryReadAllText(Application.StartupPath + "/" + path, out source)) { arguments.SetReturnValue(false); break; } success = true; } if (!success) { if (!HttpAuxiliary.TryReadAllText(path, out source)) { arguments.SetReturnValue(false); break; } } if (File.Exists(path)) { path = Path.GetFullPath(path); } arguments.SetReturnValue(machine.Run(source, path)); } while (false); } } }
private static void ____nsjsdotnet_framework_object_isdefined(NSJSVirtualMachine machine) { machine.Run(@" function ____nsjsdotnet_framework_object_isdefined(obj, key) { 'use strict' if(obj === null || obj === undefined) { return 0; } return (obj.hasOwnProperty(key) ? 1 : 0); }"); }
private static void ____nsjsdotnet_framework_object_getpropertynames(NSJSVirtualMachine machine) { machine.Run(@" function ____nsjsdotnet_framework_object_getpropertynames(obj) { 'use strict' if(obj === null || obj === undefined) { return new Array(); } return Object.getOwnPropertyNames(obj); }"); }
private static void ____nsjsdotnet_framework_instanceof(NSJSVirtualMachine machine) { machine.Run(@" function ____nsjsdotnet_framework_instanceof(instance, type) { 'use strict' if (typeof type === 'string') { try { type = eval(type); } catch (e) { return false; } } if (typeof type !== 'function') { return 0; } var x1 = instance instanceof type; if (x1) { return 1; } var x2 = 0; if (instance !== null && instance !== undefined) { var current = instance.constructor; if (current === type) { return 1; } var __instproto__ = instance; var __typesource = type.toString(); if (current && current.toString() === __typesource) { return 1; } do { __instproto__ = __instproto__.__proto__; if (__instproto__) { x2 = __instproto__.constructor === type; if (x2) { return 1; } x2 = __typesource === __instproto__.constructor.toString(); if (x2) { return 1; } } } while (__instproto__); } return (x1 || x2) ? 1 : 0; }"); }
private static void ____nsjsdotnet_framework_object_defineproperty(NSJSVirtualMachine machine) { machine.Run(@" function ____nsjsdotnet_framework_object_defineproperty(obj, key, get, set) { 'use strict' var sink = new Object(); if(set) { sink['set'] = set; } if(get) { sink['get'] = get; } Object.defineProperty(obj, key, sink); }"); }
private static void ____nsjsdotnet_framework_object_getpropertydescriptor(NSJSVirtualMachine machine) { machine.Run(@" function ____nsjsdotnet_framework_object_getpropertydescriptor(obj, key) { 'use strict' if(obj === null || obj === undefined) { return null; } if(typeof key !== 'string') { return null; } var result = Object.getOwnPropertyDescriptor(obj, key); if(!result) { return null; } return result; }"); }