Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: src/contexts.h

Issue 705663004: harmony_scoping: Implement lexical bindings at top level (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_CONTEXTS_H_ 5 #ifndef V8_CONTEXTS_H_
6 #define V8_CONTEXTS_H_ 6 #define V8_CONTEXTS_H_
7 7
8 #include "src/heap/heap.h" 8 #include "src/heap/heap.h"
9 #include "src/objects.h" 9 #include "src/objects.h"
10 10
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 V(NATIVE_OBJECT_NOTIFIER_PERFORM_CHANGE, JSFunction, \ 176 V(NATIVE_OBJECT_NOTIFIER_PERFORM_CHANGE, JSFunction, \
177 native_object_notifier_perform_change) \ 177 native_object_notifier_perform_change) \
178 V(SLOPPY_GENERATOR_FUNCTION_MAP_INDEX, Map, sloppy_generator_function_map) \ 178 V(SLOPPY_GENERATOR_FUNCTION_MAP_INDEX, Map, sloppy_generator_function_map) \
179 V(STRICT_GENERATOR_FUNCTION_MAP_INDEX, Map, strict_generator_function_map) \ 179 V(STRICT_GENERATOR_FUNCTION_MAP_INDEX, Map, strict_generator_function_map) \
180 V(GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX, Map, generator_object_prototype_map) \ 180 V(GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX, Map, generator_object_prototype_map) \
181 V(ITERATOR_RESULT_MAP_INDEX, Map, iterator_result_map) \ 181 V(ITERATOR_RESULT_MAP_INDEX, Map, iterator_result_map) \
182 V(MAP_ITERATOR_MAP_INDEX, Map, map_iterator_map) \ 182 V(MAP_ITERATOR_MAP_INDEX, Map, map_iterator_map) \
183 V(SET_ITERATOR_MAP_INDEX, Map, set_iterator_map) \ 183 V(SET_ITERATOR_MAP_INDEX, Map, set_iterator_map) \
184 V(ITERATOR_SYMBOL_INDEX, Symbol, iterator_symbol) \ 184 V(ITERATOR_SYMBOL_INDEX, Symbol, iterator_symbol) \
185 V(UNSCOPABLES_SYMBOL_INDEX, Symbol, unscopables_symbol) \ 185 V(UNSCOPABLES_SYMBOL_INDEX, Symbol, unscopables_symbol) \
186 V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) 186 V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) \
187 V(GLOBAL_CONTEXT_TABLE_INDEX, GlobalContextTable, global_context_table)
188
189
190 // A table of all global contexts. Every loaded top-level script with top-level
191 // lexical declarations contributes its GlobalContext into this table.
192 //
193 // The table is a fixed array, its first slot is current size and the subsequent
194 // slots 1..size contain GlobalContexts.
195 class GlobalContextTable : public FixedArray {
196 public:
197 // Conversions.
198 static GlobalContextTable* cast(Object* context) {
199 DCHECK(context->IsGlobalContextTable());
200 return reinterpret_cast<GlobalContextTable*>(context);
201 }
202
203 struct LookupResult {
204 int context_index;
205 int slot_index;
206 VariableMode mode;
207 InitializationFlag init_flag;
208 MaybeAssignedFlag maybe_assigned_flag;
209 };
210
211 int size() const { return Smi::cast(get(kSizeSlot))->value(); }
212
213 static Handle<Context> GetContext(Handle<GlobalContextTable> table, int i) {
214 DCHECK(i < table->size());
215 return Handle<Context>::cast(FixedArray::get(table, i + 1));
216 }
217
218 // Lookup a variable `name` in a GlobalContextTable.
219 // If it returns true, the variable is found and `result` contains
220 // valid information about its location.
221 // If it returns false, `result` is untouched.
222 MUST_USE_RESULT
223 static bool Lookup(Handle<GlobalContextTable> table, Handle<String> name,
224 LookupResult* result);
225
226 MUST_USE_RESULT
227 static Handle<GlobalContextTable> Extend(Handle<GlobalContextTable> table,
228 Handle<Context> global_context);
229
230 private:
231 static const int kSizeSlot = 0;
232
233 DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalContextTable);
234 };
187 235
188 // JSFunctions are pairs (context, function code), sometimes also called 236 // JSFunctions are pairs (context, function code), sometimes also called
189 // closures. A Context object is used to represent function contexts and 237 // closures. A Context object is used to represent function contexts and
190 // dynamically pushed 'with' contexts (or 'scopes' in ECMA-262 speak). 238 // dynamically pushed 'with' contexts (or 'scopes' in ECMA-262 speak).
191 // 239 //
192 // At runtime, the contexts build a stack in parallel to the execution 240 // At runtime, the contexts build a stack in parallel to the execution
193 // stack, with the top-most context being the current context. All contexts 241 // stack, with the top-most context being the current context. All contexts
194 // have the following slots: 242 // have the following slots:
195 // 243 //
196 // [ closure ] This is the current function. It is the same for all 244 // [ closure ] This is the current function. It is the same for all
(...skipping 25 matching lines...) Expand all
222 // we always have a context pointer). 270 // we always have a context pointer).
223 // 271 //
224 // In addition, function contexts may have statically allocated context slots 272 // In addition, function contexts may have statically allocated context slots
225 // to store local variables/functions that are accessed from inner functions 273 // to store local variables/functions that are accessed from inner functions
226 // (via static context addresses) or through 'eval' (dynamic context lookups). 274 // (via static context addresses) or through 'eval' (dynamic context lookups).
227 // The native context contains additional slots for fast access to native 275 // The native context contains additional slots for fast access to native
228 // properties. 276 // properties.
229 // 277 //
230 // Finally, with Harmony scoping, the JSFunction representing a top level 278 // Finally, with Harmony scoping, the JSFunction representing a top level
231 // script will have the GlobalContext rather than a FunctionContext. 279 // script will have the GlobalContext rather than a FunctionContext.
280 // Global contexts from all top-level scripts are gathered in
281 // GlobalContextTable.
232 282
233 class Context: public FixedArray { 283 class Context: public FixedArray {
234 public: 284 public:
235 // Conversions. 285 // Conversions.
236 static Context* cast(Object* context) { 286 static Context* cast(Object* context) {
237 DCHECK(context->IsContext()); 287 DCHECK(context->IsContext());
238 return reinterpret_cast<Context*>(context); 288 return reinterpret_cast<Context*>(context);
239 } 289 }
240 290
241 // The default context slot layout; indices are FixedArray slot indices. 291 // The default context slot layout; indices are FixedArray slot indices.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 NATIVE_OBJECT_NOTIFIER_PERFORM_CHANGE, 403 NATIVE_OBJECT_NOTIFIER_PERFORM_CHANGE,
354 SLOPPY_GENERATOR_FUNCTION_MAP_INDEX, 404 SLOPPY_GENERATOR_FUNCTION_MAP_INDEX,
355 STRICT_GENERATOR_FUNCTION_MAP_INDEX, 405 STRICT_GENERATOR_FUNCTION_MAP_INDEX,
356 GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX, 406 GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX,
357 ITERATOR_RESULT_MAP_INDEX, 407 ITERATOR_RESULT_MAP_INDEX,
358 MAP_ITERATOR_MAP_INDEX, 408 MAP_ITERATOR_MAP_INDEX,
359 SET_ITERATOR_MAP_INDEX, 409 SET_ITERATOR_MAP_INDEX,
360 ITERATOR_SYMBOL_INDEX, 410 ITERATOR_SYMBOL_INDEX,
361 UNSCOPABLES_SYMBOL_INDEX, 411 UNSCOPABLES_SYMBOL_INDEX,
362 ARRAY_VALUES_ITERATOR_INDEX, 412 ARRAY_VALUES_ITERATOR_INDEX,
413 GLOBAL_CONTEXT_TABLE_INDEX,
363 414
364 // Properties from here are treated as weak references by the full GC. 415 // Properties from here are treated as weak references by the full GC.
365 // Scavenge treats them as strong references. 416 // Scavenge treats them as strong references.
366 OPTIMIZED_FUNCTIONS_LIST, // Weak. 417 OPTIMIZED_FUNCTIONS_LIST, // Weak.
367 OPTIMIZED_CODE_LIST, // Weak. 418 OPTIMIZED_CODE_LIST, // Weak.
368 DEOPTIMIZED_CODE_LIST, // Weak. 419 DEOPTIMIZED_CODE_LIST, // Weak.
369 MAP_CACHE_INDEX, // Weak. 420 MAP_CACHE_INDEX, // Weak.
370 NEXT_CONTEXT_LINK, // Weak. 421 NEXT_CONTEXT_LINK, // Weak.
371 422
372 // Total number of slots. 423 // Total number of slots.
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 static bool IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object); 603 static bool IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object);
553 #endif 604 #endif
554 605
555 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); 606 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize);
556 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); 607 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex);
557 }; 608 };
558 609
559 } } // namespace v8::internal 610 } } // namespace v8::internal
560 611
561 #endif // V8_CONTEXTS_H_ 612 #endif // V8_CONTEXTS_H_
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | src/contexts.cc » ('j') | src/contexts.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698