Exemple #1
0
		/// <summary>
		/// Sets the
		/// <see cref="ModuleScriptProvider">ModuleScriptProvider</see>
		/// for the
		/// <see cref="Require">Require</see>
		/// instances
		/// that this builder builds.
		/// </summary>
		/// <param name="moduleScriptProvider">
		/// the module script provider for the
		/// <see cref="Require">Require</see>
		/// instances that this builder builds.
		/// </param>
		/// <returns>this, so you can chain ("fluidize") setter invocations</returns>
		public virtual RequireBuilder SetModuleScriptProvider(ModuleScriptProvider moduleScriptProvider)
		{
			this.moduleScriptProvider = moduleScriptProvider;
			return this;
		}
Exemple #2
0
		/// <summary>Creates a new instance of the require() function.</summary>
		/// <remarks>
		/// Creates a new instance of the require() function. Upon constructing it,
		/// you will either want to install it in the global (or some other) scope
		/// using
		/// <see cref="Install(Rhino.Scriptable)">Install(Rhino.Scriptable)</see>
		/// , or alternatively, you can load the
		/// program's main module using
		/// <see cref="RequireMain(Rhino.Context, string)">RequireMain(Rhino.Context, string)</see>
		/// and
		/// then act on the main module's exports.
		/// </remarks>
		/// <param name="cx">the current context</param>
		/// <param name="nativeScope">
		/// a scope that provides the standard native JavaScript
		/// objects.
		/// </param>
		/// <param name="moduleScriptProvider">a provider for module scripts</param>
		/// <param name="preExec">
		/// an optional script that is executed in every module's
		/// scope before its module script is run.
		/// </param>
		/// <param name="postExec">
		/// an optional script that is executed in every module's
		/// scope after its module script is run.
		/// </param>
		/// <param name="sandboxed">
		/// if set to true, the require function will be sandboxed.
		/// This means that it doesn't have the "paths" property, and also that the
		/// modules it loads don't export the "module.uri" property.
		/// </param>
		public Require(Context cx, Scriptable nativeScope, ModuleScriptProvider moduleScriptProvider, Script preExec, Script postExec, bool sandboxed)
		{
			// Modules that completed loading; visible to all threads
			// Modules currently being loaded on the thread. Used to resolve circular
			// dependencies while loading.
			this.moduleScriptProvider = moduleScriptProvider;
			this.nativeScope = nativeScope;
			this.sandboxed = sandboxed;
			this.preExec = preExec;
			this.postExec = postExec;
			SetPrototype(ScriptableObject.GetFunctionPrototype(nativeScope));
			if (!sandboxed)
			{
				paths = cx.NewArray(nativeScope, 0);
				DefineReadOnlyProperty(this, "paths", paths);
			}
			else
			{
				paths = null;
			}
		}