private JsSchema(JsSchema schema) { #if SCHEMA_STATISTICS _createdSchemas++; #endif _freeList = schema._freeList; _arraySize = schema._arraySize; }
public bool DeleteProperty(int index, bool strict) { PropertyAttributes attributes; if (!Schema.TryGetAttributes(index, out attributes)) return true; if ((attributes & PropertyAttributes.DontDelete) == 0) { Schema = Schema.Remove(index, ref _values); return true; } if (strict) throw new JsException(JsErrorType.TypeError, "Property " + index + " isn't configurable"); return false; }
private static void QueueFlattenSchema(JsSchema schema) { bool startThread = false; // Push the schema onto the pending queue. lock (_syncRoot) { _pendingFlatten = new PendingFlatten(schema, _pendingFlatten); // If the thread isn't running, we need to start it. if (!_flattenThreadRunning) { _flattenThreadRunning = true; startThread = true; } } if (startThread) ThreadPool.QueueUserWorkItem(p => FlattenSchemaThread()); }
public JsGlobal(JintRuntime runtime, JintEngine engine) { if (runtime == null) throw new ArgumentNullException("runtime"); _runtime = runtime; Id.SeedGlobal(this); PrototypeSink = CreatePrototypeSink(); RootSchema = new JsSchema(); Engine = engine; // The Random instance is used by Math to generate random numbers. Random = new Random(); BuildEnvironment(); GlobalScope = CreateGlobalScope(); Marshaller = new Marshaller(runtime, this); Marshaller.Initialize(); }
internal DictionaryCacheSlot(JsSchema schema, int index) { _schema = schema; _index = index; }
public JsSchema Add(int index, PropertyAttributes attributes, ref object[] values, object value) { // The entry shouldn't be in our schema yet. Debug.Assert(GetOffset(index) < 0); // Get or create the new schema. JsSchema schema = null; // Check whether we already have a transformation. if (_transformations != null) schema = _transformations.GetValue(MakeIndex(index, attributes)); int newOffset; // Build the new schema if we don't have it yet and add it to the // list of transformations. if (schema == null) { schema = new JsSchema(this); // Apply the mutation to the new schema. We get a free entry or, // if there isn't any, increase the array size. var freeList = schema._freeList; if (freeList == null) { schema.GrowFreeEntries(); freeList = schema._freeList; } schema._freeList = freeList.Next; newOffset = freeList.Index; schema._node = new Node(true, index, attributes, newOffset, _node); if (_transformations == null) _transformations = new SchemaTransformationHashSet(InitialTransformationsSize); _transformations.Add(MakeIndex(index, attributes), schema); } else { newOffset = schema.GetOffset(index); // The attributes of this property of the new schema should // be the same as what we're adding. Debug.Assert(schema.GetAttributes(index) == attributes); } // Apply the transformation to the values array. if (_arraySize != schema._arraySize) Array.Resize(ref values, schema._arraySize); values[newOffset] = value; return schema; }
public JsSchema Remove(int index, ref object[] values) { int oldOffset = GetOffset(index); // The entry should be in our schema. Debug.Assert(oldOffset >= 0); // Get or create the new schema. JsSchema schema = null; // Check whether we already have a transformation. if (_transformations != null) schema = _transformations.GetValue(MakeIndex(index, 0)); // Build the new schema if we don't have it yet and add it to the // list of transformations. if (schema == null) { schema = new JsSchema(this); // Apply the transformation to the schema and add the index to // the free list. schema._node = new Node(false, index, 0, -1, _node); schema._freeList = new FreeEntry(oldOffset, schema._freeList); // Add the transformation. if (_transformations == null) _transformations = new SchemaTransformationHashSet(); _transformations.Add(MakeIndex(index, 0), schema); } // Apply the transformation to the values array. values[oldOffset] = null; return schema; }
public void Invalidate() { _value = null; }
public Entry(int index, JsSchema value, int next) { Debug.Assert(value != null); _index = index; _value = value; _next = next; }
public void Add(int index, JsSchema value) { int entryIndex = FindEntry(index); if (entryIndex >= 0) throw new ArgumentOutOfRangeException("index"); // Grow the entries when we have to. if (Count >= MaxLoadFactor) GrowEntries(); // If the entry at the ideal location doesn't have the correct has, // we're going to move that entry. int hash = Hash(index); if (_entries[hash].IsValid && Hash(_entries[hash].Index) != hash) { // Create a copy of the current entry and remove it. var copy = _entries[hash]; Remove(copy.Index); // Put the new entry at the ideal location. _entries[hash] = new Entry(index, value, -1); // Increment the count. Count++; // And now add the previous entry. Add(copy.Index, copy.Value); } else { // Find the end of the chain currently at the entry. entryIndex = Hash(index); int free; if (_entries[entryIndex].IsValid) { for ( int next = _entries[entryIndex].Next; next != -1; entryIndex = next, next = _entries[entryIndex].Next ) { // Find the end of the chain. } // Find a free entry. free = entryIndex + 1; int length = _entries.Length; while (true) { if (free == length) free = 0; if (!_entries[free].IsValid) break; free++; } } else { free = entryIndex; entryIndex = -1; } // Put the new entry into the free location. _entries[free] = new Entry(index, value, -1); // Fixup the chain if we have one. if (entryIndex >= 0) _entries[entryIndex].Next = free; // Increment the count. Count++; } }
public void DefineProperty(int index, object value, PropertyAttributes attributes) { Debug.Assert(GetOwnPropertyRaw(index) == null); Schema = Schema.Add(index, attributes, ref _values, value); }
public PendingFlatten(JsSchema schema, PendingFlatten parent) { Schema = schema; Parent = parent; }