public virtual void initFromContext (Context cx) { setErrorReporter (cx.ErrorReporter); this.languageVersion = cx.Version; useDynamicScope = cx.compileFunctionsWithDynamicScopeFlag; generateDebugInfo = (!cx.GeneratingDebugChanged || cx.GeneratingDebug); reservedKeywordAsIdentifier = cx.HasFeature (Context.Features.ReservedKeywordAsIdentifier); allowMemberExprAsFunctionName = cx.HasFeature (Context.Features.MemberExprAsFunctionName); xmlAvailable = cx.HasFeature (Context.Features.E4x); getterAndSetterSupport = cx.HasFeature (Context.Features.GetterAndSetter); optimizationLevel = cx.OptimizationLevel; generatingSource = cx.GeneratingSource; activationNames = cx.activationNames; }
internal static IRef createSpecial (Context cx, object obj, string name) { IScriptable target = ScriptConvert.ToObjectOrNull (cx, obj); if (target == null) { throw ScriptRuntime.UndefReadError (obj, name); } Types type; if (name.Equals ("__proto__")) { type = Types.Proto; } else if (name.Equals ("__parent__")) { type = Types.Parent; } else { throw new ArgumentException (name); } if (!cx.HasFeature (Context.Features.ParentProtoProperties)) { // Clear special after checking for valid name! type = Types.None; } return new SpecialRef (target, type, name); }
/// <summary> The eval function property of the global object. /// /// See ECMA 15.1.2.1 /// </summary> public static object evalSpecial(Context cx, IScriptable scope, object thisArg, object [] args, string filename, int lineNumber) { if (args.Length < 1) return Undefined.Value; object x = args [0]; if (!(x is string)) { if (cx.HasFeature (Context.Features.StrictEval)) { throw Context.ReportRuntimeErrorById ("msg.eval.nonstring.strict"); } string message = ScriptRuntime.GetMessage ("msg.eval.nonstring"); Context.ReportWarning (message); return x; } if (filename == null) { int [] linep = new int [1]; filename = Context.GetSourcePositionFromStack (linep); if (filename != null) { lineNumber = linep [0]; } else { filename = ""; } } string sourceName = ScriptRuntime.makeUrlForGeneratedScript (true, filename, lineNumber); ErrorReporter reporter; reporter = DefaultErrorReporter.ForEval (cx.ErrorReporter); // Compile with explicit interpreter instance to force interpreter // mode. IScript script = cx.CompileString ((string)x, new Interpreter (), reporter, sourceName, 1, (object)null); ((InterpretedFunction)script).idata.evalScriptFlag = true; ICallable c = (ICallable)script; return c.Call (cx, scope, (IScriptable)thisArg, ScriptRuntime.EmptyArgs); }
public static object DoTopCall(ICallable callable, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (scope == null) throw new ArgumentException (); if (cx.topCallScope != null) throw new ApplicationException (); object result; cx.topCallScope = ScriptableObject.GetTopLevelScope (scope); cx.useDynamicScope = cx.HasFeature (Context.Features.DynamicScope); ContextFactory f = cx.Factory; try { result = f.DoTopCall (callable, cx, scope, thisObj, args); } finally { cx.topCallScope = null; // Cleanup cached references cx.cachedXMLLib = null; if (cx.currentActivationCall != null) { // Function should always call exitActivationFunction // if it creates activation record throw new ApplicationException ( "ActivationCall without exitActivationFunction() invokation." ); } } return result; }
public static object setName(IScriptable bound, object value, Context cx, IScriptable scope, string id) { if (bound != null) { if (bound is XMLObject) { XMLObject xmlObject = (XMLObject)bound; xmlObject.EcmaPut (cx, id, value); } else { ScriptableObject.PutProperty (bound, id, value); } } else { // "newname = 7;", where 'newname' has not yet // been defined, creates a new property in the // top scope unless strict mode is specified. if (cx.HasFeature (Context.Features.StrictVars)) { throw Context.ReportRuntimeErrorById ("msg.assn.create.strict", id); } // Find the top scope by walking up the scope chain. bound = ScriptableObject.GetTopLevelScope (scope); if (cx.useDynamicScope) { bound = checkDynamicScope (cx.topCallScope, bound); } bound.Put (id, bound, value); } return value; }
public static ScriptableObject InitStandardObjects(Context cx, ScriptableObject scope, bool zealed) { if (scope == null) { scope = new BuiltinObject (); } scope.AssociateValue (LIBRARY_SCOPE_KEY, scope); BaseFunction.Init (scope, zealed); BuiltinObject.Init (scope, zealed); IScriptable objectProto = ScriptableObject.GetObjectPrototype (scope); // Function.prototype.__proto__ should be Object.prototype IScriptable functionProto = ScriptableObject.GetFunctionPrototype (scope); functionProto.SetPrototype (objectProto); // Set the prototype of the object passed in if need be if (scope.GetPrototype () == null) scope.SetPrototype (objectProto); // must precede NativeGlobal since it's needed therein BuiltinError.Init (scope, zealed); BuiltinGlobal.Init (cx, scope, zealed); if (scope is BuiltinGlobalObject) { ((BuiltinGlobalObject)scope).Init (scope, zealed); } BuiltinArray.Init (scope, zealed); BuiltinString.Init (scope, zealed); BuiltinBoolean.Init (scope, zealed); BuiltinNumber.Init (scope, zealed); BuiltinDate.Init (scope, zealed); BuiltinMath.Init (scope, zealed); BuiltinWith.Init (scope, zealed); BuiltinCall.Init (scope, zealed); BuiltinScript.Init (scope, zealed); BuiltinRegExp.Init (scope, zealed); if (cx.HasFeature (Context.Features.E4x)) { Types.E4X.XMLLib.Init (scope, zealed); } Continuation.Init (scope, zealed); if (cx.HasFeature (Context.Features.NonEcmaItObject)) { InitItObject (cx, scope); } return scope; }