public DictionaryPropertyStore(JsObject owner) { if (owner == null) throw new ArgumentNullException("owner"); Owner = owner; _global = Owner.Global; Schema = _global.RootSchema; }
public ExecutionVisitor(Options options) { typeResolver = CachedTypeResolver.Default; Global = new JsGlobal(this, options); GlobalScope = new JsScope(Global as JsObject); EnterScope(GlobalScope); CallStack = new Stack<string>(); }
public JintRuntime(JintEngine engine) { if (engine == null) throw new ArgumentNullException("engine"); _engine = engine; Global = new JsGlobal(this, engine); GlobalScope = Global.GlobalScope; }
public ExecutionVisitor(Options options) { this.methodInvoker = new CachedMethodInvoker(this); this.propertyGetter = new CachedReflectionPropertyGetter(methodInvoker); this.constructorInvoker = new CachedConstructorInvoker(methodInvoker); this.typeResolver = new CachedTypeResolver(); this.fieldGetter = new CachedReflectionFieldGetter(methodInvoker); GlobalScope = new JsObject(); Global = new JsGlobal(this, options); GlobalScope.Prototype = Global as JsDictionaryObject; EnterScope(GlobalScope); CallStack = new Stack<string>(); }
public ExecutionVisitor(Options options, IScriptEngineContext context) { this.scriptEngineContext = context; this.methodInvoker = context.GetMethodInvoker(this);//new CachedMethodInvoker(this); this.propertyGetter = new CachedReflectionPropertyGetter(methodInvoker); this.constructorInvoker = new CachedConstructorInvoker(methodInvoker); this.typeResolver = context.GetTypeResolver();//new CachedTypeResolver(); this.fieldGetter = new CachedReflectionFieldGetter(methodInvoker); _entitiyAccessor = new EntityAccessor(); GlobalScope = new JsObject(); Global = new JsGlobal(this, options); GlobalScope.Prototype = Global as JsDictionaryObject; EnterScope(GlobalScope); CallStack = new Stack<string>(); }
/// <summary> /// 8.10.5 /// </summary> private static void ToPropertyDescriptor(JsGlobal global, JsObject owner, string name, object value) { var @object = value as JsObject; if (@object == null) throw new JsException(JsErrorType.TypeError, "The target object has to be an instance of an object"); if ( (@object.HasProperty(Id.value) || @object.HasProperty(Id.writable)) && (@object.HasProperty(Id.set) || @object.HasProperty(Id.get)) ) throw new JsException(JsErrorType.TypeError, "The property cannot be both writable and have get/set accessors or cannot have both a value and an accessor defined"); var attributes = PropertyAttributes.None; JsObject getFunction = null; JsObject setFunction = null; object result; if ( @object.TryGetProperty(Id.enumerable, out result) && !JsValue.ToBoolean(result) ) attributes |= PropertyAttributes.DontEnum; if ( @object.TryGetProperty(Id.configurable, out result) && !JsValue.ToBoolean(result) ) attributes |= PropertyAttributes.DontDelete; if ( @object.TryGetProperty(Id.writable, out result) && !JsValue.ToBoolean(result) ) attributes |= PropertyAttributes.ReadOnly; if (@object.TryGetProperty(Id.get, out result)) { if (!JsValue.IsFunction(result)) throw new JsException(JsErrorType.TypeError, "The getter has to be a function"); getFunction = (JsObject)result; } if (@object.TryGetProperty(Id.set, out result)) { if (!JsValue.IsFunction(result)) throw new JsException(JsErrorType.TypeError, "The setter has to be a function"); setFunction = (JsObject)result; } if (@object.HasProperty(Id.value)) { owner.DefineProperty( global.ResolveIdentifier(name), @object.GetProperty(Id.value), PropertyAttributes.None ); } else { owner.DefineAccessor( global.ResolveIdentifier(name), getFunction, setFunction, attributes ); } }
private static void SeedToken(JsGlobal global, string name, int id) { int resolvedId = global.ResolveIdentifier(name); Debug.Assert(id == resolvedId); }
public static void SeedGlobal(JsGlobal target) { if (target == null) throw new ArgumentNullException("target"); SeedToken(target, "__lookupGetter__", __lookupGetter__); SeedToken(target, "__lookupSetter__", __lookupSetter__); SeedToken(target, "__proto__", __proto__); SeedToken(target, "abs", abs); SeedToken(target, "acos", acos); SeedToken(target, "apply", apply); SeedToken(target, "Array", Array); SeedToken(target, "asin", asin); SeedToken(target, "atan", atan); SeedToken(target, "atan2", atan2); SeedToken(target, "Boolean", Boolean); SeedToken(target, "call", call); SeedToken(target, "callee", callee); SeedToken(target, "ceil", ceil); SeedToken(target, "charAt", charAt); SeedToken(target, "charCodeAt", charCodeAt); SeedToken(target, "concat", concat); SeedToken(target, "configurable", configurable); SeedToken(target, "constructor", constructor); SeedToken(target, "cos", cos); SeedToken(target, "Date", Date); SeedToken(target, "decodeURI", decodeURI); SeedToken(target, "decodeURIComponent", decodeURIComponent); SeedToken(target, "defineProperty", defineProperty); SeedToken(target, "E", E); SeedToken(target, "encodeURI", encodeURI); SeedToken(target, "encodeURIComponent", encodeURIComponent); SeedToken(target, "enumerable", enumerable); SeedToken(target, "Error", Error); SeedToken(target, "eval", eval); SeedToken(target, "EvalError", EvalError); SeedToken(target, "exec", exec); SeedToken(target, "exp", exp); SeedToken(target, "floor", floor); SeedToken(target, "fromCharCode", fromCharCode); SeedToken(target, "Function", Function); SeedToken(target, "get", get); SeedToken(target, "getDate", getDate); SeedToken(target, "getDay", getDay); SeedToken(target, "getFullYear", getFullYear); SeedToken(target, "getHours", getHours); SeedToken(target, "getMilliseconds", getMilliseconds); SeedToken(target, "getMinutes", getMinutes); SeedToken(target, "getMonth", getMonth); SeedToken(target, "getPrototypeOf", getPrototypeOf); SeedToken(target, "getSeconds", getSeconds); SeedToken(target, "getTime", getTime); SeedToken(target, "getTimezoneOffset", getTimezoneOffset); SeedToken(target, "getUTCDate", getUTCDate); SeedToken(target, "getUTCDay", getUTCDay); SeedToken(target, "getUTCFullYear", getUTCFullYear); SeedToken(target, "getUTCHours", getUTCHours); SeedToken(target, "getUTCMilliseconds", getUTCMilliseconds); SeedToken(target, "getUTCMinutes", getUTCMinutes); SeedToken(target, "getUTCMonth", getUTCMonth); SeedToken(target, "getUTCSeconds", getUTCSeconds); SeedToken(target, "global", @global); SeedToken(target, "hasOwnProperty", hasOwnProperty); SeedToken(target, "index", index); SeedToken(target, "indexOf", indexOf); SeedToken(target, "Infinity", Infinity); SeedToken(target, "input", input); SeedToken(target, "isFinite", isFinite); SeedToken(target, "isNaN", isNaN); SeedToken(target, "isPrototypeOf", isPrototypeOf); SeedToken(target, "join", join); SeedToken(target, "lastIndex", lastIndex); SeedToken(target, "lastIndexOf", lastIndexOf); SeedToken(target, "length", length); SeedToken(target, "LN10", LN10); SeedToken(target, "LN2", LN2); SeedToken(target, "localeCompare", localeCompare); SeedToken(target, "log", log); SeedToken(target, "LOG2E", LOG2E); SeedToken(target, "match", match); SeedToken(target, "Math", Math); SeedToken(target, "max", max); SeedToken(target, "MAX_VALUE", MAX_VALUE); SeedToken(target, "message", message); SeedToken(target, "min", min); SeedToken(target, "MIN_VALUE", MIN_VALUE); SeedToken(target, "name", name); SeedToken(target, "NaN", NaN); SeedToken(target, "NEGATIVE_INFINITY", NEGATIVE_INFINITY); SeedToken(target, "now", now); SeedToken(target, "null", @null); SeedToken(target, "Number", Number); SeedToken(target, "Object", Object); SeedToken(target, "parse", parse); SeedToken(target, "parseFloat", parseFloat); SeedToken(target, "parseInt", parseInt); SeedToken(target, "parseLocale", parseLocale); SeedToken(target, "PI", PI); SeedToken(target, "pop", pop); SeedToken(target, "POSITIVE_INFINITY", POSITIVE_INFINITY); SeedToken(target, "pow", pow); SeedToken(target, "propertyIsEnumerable", propertyIsEnumerable); SeedToken(target, "prototype", prototype); SeedToken(target, "push", push); SeedToken(target, "random", random); SeedToken(target, "RangeError", RangeError); SeedToken(target, "ReferenceError", ReferenceError); SeedToken(target, "RegExp", RegExp); SeedToken(target, "replace", replace); SeedToken(target, "reverse", reverse); SeedToken(target, "round", round); SeedToken(target, "search", search); SeedToken(target, "set", set); SeedToken(target, "setDate", setDate); SeedToken(target, "setFullYear", setFullYear); SeedToken(target, "setHours", setHours); SeedToken(target, "setMilliseconds", setMilliseconds); SeedToken(target, "setMinutes", setMinutes); SeedToken(target, "setMonth", setMonth); SeedToken(target, "setSeconds", setSeconds); SeedToken(target, "setTime", setTime); SeedToken(target, "setUTCDate", setUTCDate); SeedToken(target, "setUTCFullYear", setUTCFullYear); SeedToken(target, "setUTCHours", setUTCHours); SeedToken(target, "setUTCMilliseconds", setUTCMilliseconds); SeedToken(target, "setUTCMinutes", setUTCMinutes); SeedToken(target, "setUTCMonth", setUTCMonth); SeedToken(target, "setUTCSeconds", setUTCSeconds); SeedToken(target, "shift", shift); SeedToken(target, "sin", sin); SeedToken(target, "slice", slice); SeedToken(target, "sort", sort); SeedToken(target, "source", source); SeedToken(target, "splice", splice); SeedToken(target, "split", split); SeedToken(target, "sqrt", sqrt); SeedToken(target, "SQRT1_2", SQRT1_2); SeedToken(target, "SQRT2", SQRT2); SeedToken(target, "String", String); SeedToken(target, "substr", substr); SeedToken(target, "substring", substring); SeedToken(target, "SyntaxError", SyntaxError); SeedToken(target, "tan", tan); SeedToken(target, "test", test); SeedToken(target, "this", @this); SeedToken(target, "ToBoolean", ToBoolean); SeedToken(target, "ToByte", ToByte); SeedToken(target, "ToChar", ToChar); SeedToken(target, "toDateString", toDateString); SeedToken(target, "ToDateTime", ToDateTime); SeedToken(target, "ToDecimal", ToDecimal); SeedToken(target, "ToDouble", ToDouble); SeedToken(target, "toExponential", toExponential); SeedToken(target, "toFixed", toFixed); SeedToken(target, "ToInt16", ToInt16); SeedToken(target, "ToInt32", ToInt32); SeedToken(target, "ToInt64", ToInt64); SeedToken(target, "toLocaleDateString", toLocaleDateString); SeedToken(target, "toLocaleLowerCase", toLocaleLowerCase); SeedToken(target, "toLocaleString", toLocaleString); SeedToken(target, "toLocaleTimeString", toLocaleTimeString); SeedToken(target, "toLocaleUpperCase", toLocaleUpperCase); SeedToken(target, "toLowerCase", toLowerCase); SeedToken(target, "toPrecision", toPrecision); SeedToken(target, "ToSByte", ToSByte); SeedToken(target, "ToSingle", ToSingle); SeedToken(target, "toString", toString); SeedToken(target, "ToString", ToString); SeedToken(target, "toTimeString", toTimeString); SeedToken(target, "ToUInt16", ToUInt16); SeedToken(target, "ToUInt32", ToUInt32); SeedToken(target, "ToUInt64", ToUInt64); SeedToken(target, "toUpperCase", toUpperCase); SeedToken(target, "toUTCString", toUTCString); SeedToken(target, "TypeError", TypeError); SeedToken(target, "undefined", undefined); SeedToken(target, "unshift", unshift); SeedToken(target, "URIError", URIError); SeedToken(target, "UTC", UTC); SeedToken(target, "value", value); SeedToken(target, "valueOf", valueOf); SeedToken(target, "writable", writable); }
private static bool ParseDate(JsGlobal global, string value, IFormatProvider culture, out double result) { result = 0; DateTime date; if (DateTime.TryParse(value, culture, DateTimeStyles.None, out date)) { result = global.CreateDate(date).ToNumber(); return true; } if (DateTime.TryParseExact(value, JsNames.DateTimeFormat, culture, DateTimeStyles.None, out date)) { result = global.CreateDate(date).ToNumber(); return true; } DateTime ld; if (DateTime.TryParseExact(value, JsNames.DateFormat, culture, DateTimeStyles.None, out ld)) date = date.AddTicks(ld.Ticks); if (DateTime.TryParseExact(value, JsNames.TimeFormat, culture, DateTimeStyles.None, out ld)) date = date.AddTicks(ld.Ticks); if (date.Ticks > 0) { result = global.CreateDate(date).ToNumber(); return true; } return true; }