InitStandardObjects() public method

Initialize the standard objects.
Initialize the standard objects. Creates instances of the standard objects and their constructors (Object, String, Number, Date, etc.), setting up 'scope' to act as a global object as in ECMA 15.1.

This method must be called to initialize a scope before scripts can be evaluated in that scope.

This method does not affect the Context it is called upon.

public InitStandardObjects ( ScriptableObject scope ) : Scriptable
scope ScriptableObject /// the scope to initialize, or null, in which case a new /// object will be created to serve as the scope ///
return Scriptable
Example #1
0
			public object Run(Context cx)
			{
				cx.GetWrapFactory().SetJavaPrimitiveWrap(false);
				NUnit.Framework.Assert.AreEqual("string[]", cx.EvaluateString(cx.InitStandardObjects(), "new org.mozilla.javascript.tests.Bug496585Test().method('one', 'two', 'three')", "<test>", 1, null));
				NUnit.Framework.Assert.AreEqual("string+function", cx.EvaluateString(cx.InitStandardObjects(), "new org.mozilla.javascript.tests.Bug496585Test().method('one', function() {})", "<test>", 1, null));
				return null;
			}
			public object Run(Context cx)
			{
				Scriptable scope1 = cx.InitStandardObjects(new PrimitiveTypeScopeResolutionTest.MySimpleScriptableObject("scope1"));
				Scriptable scope2 = cx.InitStandardObjects(new PrimitiveTypeScopeResolutionTest.MySimpleScriptableObject("scope2"));
				cx.EvaluateString(scope2, scriptScope2, "source2", 1, null);
				scope1.Put("scope2", scope1, scope2);
				return cx.EvaluateString(scope1, scriptScope1, "source1", 1, null);
			}
			public object Run(Context cx)
			{
				ScriptableObject top = cx.InitStandardObjects();
				ScriptableObject.PutProperty(top, "foo", foo);
				cx.EvaluateString(top, script, "script", 0, null);
				return null;
			}
Example #4
0
			public object Run(Context _cx)
			{
				ScriptableObject scope = _cx.InitStandardObjects();
				object result = _cx.EvaluateString(scope, script, "test script", 0, null);
				NUnit.Framework.Assert.AreEqual("b1,b2,a0,a1,,a3", Context.ToString(result));
				return null;
			}
Example #5
0
			public object Run(Context cx)
			{
				Scriptable scope = cx.InitStandardObjects();
				object rep = cx.EvaluateString(scope, source, "test.js", 0, null);
				NUnit.Framework.Assert.AreEqual(expected, rep);
				return null;
			}
Example #6
0
			public object Run(Context cx)
			{
				Scriptable scope = cx.InitStandardObjects();
				try
				{
					cx.EvaluateString(scope, _source, "test.js", 0, null);
				}
				catch (JavaScriptException e)
				{
					NUnit.Framework.Assert.AreEqual(_expectedStackTrace, e.GetScriptStackTrace());
					return null;
				}
				throw new Exception("Exception expected!");
			}
Example #7
0
		public virtual void InitStandardObjects(Context cx, bool @sealed)
		{
			// Assume that Context.initStandardObjects initialize JavaImporter
			// property lazily so the above init call is not yet called
			cx.InitStandardObjects(this, @sealed);
			topScopeFlag = true;
			// If seal is true then exportAsJSClass(cx, seal) would seal
			// this obj. Since this is scope as well, it would not allow
			// to add variables.
			IdFunctionObject ctor = ExportAsJSClass(MAX_PROTOTYPE_ID, this, false);
			if (@sealed)
			{
				ctor.SealObject();
			}
			// delete "constructor" defined by exportAsJSClass so "constructor"
			// name would refer to Object.constructor
			// and not to JavaImporter.prototype.constructor.
			Delete("constructor");
		}
Example #8
0
		public virtual void SetUp()
		{
			cx = Context.Enter();
			cx.SetOptimizationLevel(-1);
			scope = cx.InitStandardObjects();
		}
Example #9
0
			public object Run(Context _cx)
			{
				ScriptableObject scope = _cx.InitStandardObjects();
				object result = _cx.EvaluateString(scope, script, "test script", 0, null);
				return null;
			}
Example #10
0
			public object Run(Context cx)
			{
				this.cx = cx;
				scope = cx.InitStandardObjects(null, true);
				return Run();
			}
Example #11
0
		public virtual void SetUp()
		{
			cx = Context.Enter();
			scope = cx.InitStandardObjects();
			cx.SetLanguageVersion(170);
		}
Example #12
0
			public object Run(Context context)
			{
				Scriptable scope = context.InitStandardObjects();
				scope.Put("myObj", scope, f);
				return context.EvaluateString(scope, "typeof myObj", "test script", 1, null);
			}
Example #13
0
			public object Run(Context context)
			{
				Scriptable scope = context.InitStandardObjects();
				return context.EvaluateString(scope, script, "test script", 1, null);
			}
Example #14
0
		public virtual void SetUp()
		{
			cx = Context.Enter();
			scope = cx.InitStandardObjects();
		}
Example #15
0
			public object Run(Context cx)
			{
				try
				{
					ScriptableObject scope = cx.InitStandardObjects();
					object o = cx.EvaluateString(scope, script, "myScript.js", 1, null);
					NUnit.Framework.Assert.AreEqual(expected, o);
					return o;
				}
				catch (Exception e)
				{
					throw;
				}
				catch (Exception e)
				{
					throw new Exception(e);
				}
			}
Example #16
0
		public virtual void SetUp()
		{
			cx = Context.Enter();
			parser = new JsonParser(cx, cx.InitStandardObjects());
		}
Example #17
0
		/// <exception cref="Sharpen.URISyntaxException"></exception>
		private Require GetSandboxedRequire(Context cx, Scriptable scope, bool sandboxed)
		{
			return new Require(cx, cx.InitStandardObjects(), new StrongCachingModuleScriptProvider(new UrlModuleSourceProvider(Collections.Singleton(GetDirectory()), null)), null, null, true);
		}
Example #18
0
		/// <exception cref="Sharpen.URISyntaxException"></exception>
		private Require GetSandboxedRequire(Context cx)
		{
			return GetSandboxedRequire(cx, cx.InitStandardObjects(), true);
		}
Example #19
0
			public object Run(Context cx)
			{
				Scriptable scope = cx.InitStandardObjects();
				return cx.EvaluateString(scope, script, "myScript.js", 1, null);
			}