internal static Rhino.NativeGenerator Init(ScriptableObject scope, bool @sealed) { // Generator // Can't use "NativeGenerator().exportAsJSClass" since we don't want // to define "Generator" as a constructor in the top-level scope. Rhino.NativeGenerator prototype = new Rhino.NativeGenerator(); if (scope != null) { prototype.SetParentScope(scope); prototype.SetPrototype(GetObjectPrototype(scope)); } prototype.ActivatePrototypeMap(MAX_PROTOTYPE_ID); if (@sealed) { prototype.SealObject(); } // Need to access Generator prototype when constructing // Generator instances, but don't have a generator constructor // to use to find the prototype. Use the "associateValue" // approach instead. if (scope != null) { scope.AssociateValue(GENERATOR_TAG, prototype); } return prototype; }
internal XMLLib BindToScope(IScriptable scope) { ScriptableObject so = ScriptRuntime.getLibraryScopeOrNull(scope); if (so == null) { // standard library should be initialized at this point throw new Exception(); } return((XMLLib)so.AssociateValue(XML_LIB_KEY, this)); }
internal static void Init(ScriptableObject scope, bool @sealed) { // Iterator Rhino.NativeIterator iterator = new Rhino.NativeIterator(); iterator.ExportAsJSClass(MAX_PROTOTYPE_ID, scope, @sealed); // Generator NativeGenerator.Init(scope, @sealed); // StopIteration NativeObject obj = new NativeIterator.StopIteration(); obj.SetPrototype(GetObjectPrototype(scope)); obj.SetParentScope(scope); if (@sealed) { obj.SealObject(); } ScriptableObject.DefineProperty(scope, STOP_ITERATION, obj, ScriptableObject.DONTENUM); // Use "associateValue" so that generators can continue to // throw StopIteration even if the property of the global // scope is replaced or deleted. scope.AssociateValue(ITERATOR_TAG, obj); }
/// <summary>Associate ClassCache object with the given top-level scope.</summary> /// <remarks> /// Associate ClassCache object with the given top-level scope. /// The ClassCache object can only be associated with the given scope once. /// </remarks> /// <param name="topScope">scope to associate this ClassCache object with.</param> /// <returns> /// true if no previous ClassCache objects were embedded into /// the scope and this ClassCache were successfully associated /// or false otherwise. /// </returns> /// <seealso cref="Get(Scriptable)">Get(Scriptable)</seealso> public virtual bool Associate(ScriptableObject topScope) { if (topScope.GetParentScope() != null) { // Can only associate cache with top level scope throw new ArgumentException(); } if (this == topScope.AssociateValue(AKEY, this)) { associatedScope = topScope; return true; } return false; }