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

Side by Side Diff: src/contexts.h

Issue 7992005: Block scoped const variables. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comments, function variable mode, preparser. Created 9 years, 2 months 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
« no previous file with comments | « src/ast.h ('k') | src/contexts.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 28 matching lines...) Expand all
39 FOLLOW_CONTEXT_CHAIN = 1, 39 FOLLOW_CONTEXT_CHAIN = 1,
40 FOLLOW_PROTOTYPE_CHAIN = 2, 40 FOLLOW_PROTOTYPE_CHAIN = 2,
41 41
42 DONT_FOLLOW_CHAINS = 0, 42 DONT_FOLLOW_CHAINS = 0,
43 FOLLOW_CHAINS = FOLLOW_CONTEXT_CHAIN | FOLLOW_PROTOTYPE_CHAIN 43 FOLLOW_CHAINS = FOLLOW_CONTEXT_CHAIN | FOLLOW_PROTOTYPE_CHAIN
44 }; 44 };
45 45
46 46
47 // ES5 10.2 defines lexical environments with mutable and immutable bindings. 47 // ES5 10.2 defines lexical environments with mutable and immutable bindings.
48 // Immutable bindings have two states, initialized and uninitialized, and 48 // Immutable bindings have two states, initialized and uninitialized, and
49 // their state is changed by the InitializeImmutableBinding method. 49 // their state is changed by the InitializeImmutableBinding method. The
50 // BindingFlags enum represents information if a binding has definitely been
51 // initialized. A mutable binding does not need to be checked and thus has
52 // the BindingFlag MUTABLE_IS_INITIALIZED.
53 //
54 // There are two possibilities for immutable bindings
55 // * 'const' declared variables. They are initialized when evaluating the
56 // corresponding declaration statement. They need to be checked for being
57 // initialized and thus get the flag IMMUTABLE_CHECK_INITIALIZED.
58 // * The function name of a named function literal. The binding is immediately
59 // initialized when entering the function and thus does not need to be
60 // checked. it gets the BindingFlag IMMUTABLE_IS_INITIALIZED.
61 // Accessing an uninitialized binding produces the undefined value.
50 // 62 //
51 // The harmony proposal for block scoped bindings also introduces the 63 // The harmony proposal for block scoped bindings also introduces the
52 // uninitialized state for mutable bindings. A 'let' declared variable 64 // uninitialized state for mutable bindings.
53 // is a mutable binding that is created uninitalized upon activation of its 65 // * A 'let' declared variable. They are initialized when evaluating the
54 // lexical environment and it is initialized when evaluating its declaration 66 // corresponding declaration statement. They need to be checked for being
55 // statement. Var declared variables are mutable bindings that are 67 // initialized and thus get the flag MUTABLE_CHECK_INITIALIZED.
56 // immediately initialized upon creation. The BindingFlags enum represents 68 // * A 'var' declared variable. It is initialized immediately upon creation
57 // information if a binding has definitely been initialized. 'const' declared 69 // and thus doesn't need to be checked. It gets the flag
58 // variables are created as uninitialized immutable bindings. 70 // MUTABLE_IS_INITIALIZED.
59 71 // * Catch bound variables, function parameters and variables introduced by
60 // In harmony mode accessing an uninitialized binding produces a reference 72 // function declarations are initialized immediately and do not need to be
61 // error. 73 // checked. Thus they get the flag MUTABLE_IS_INITIALIZED.
74 // Immutable bindings in harmony mode get the _HARMONY flag variants. Accessing
75 // an uninitialized binding produces a reference error.
76 //
77 // In V8 uninitialized bindings are set to the hole value upon creation and set
78 // to a different value upon initialization.
62 enum BindingFlags { 79 enum BindingFlags {
63 MUTABLE_IS_INITIALIZED, 80 MUTABLE_IS_INITIALIZED,
64 MUTABLE_CHECK_INITIALIZED, 81 MUTABLE_CHECK_INITIALIZED,
65 IMMUTABLE_IS_INITIALIZED, 82 IMMUTABLE_IS_INITIALIZED,
66 IMMUTABLE_CHECK_INITIALIZED, 83 IMMUTABLE_CHECK_INITIALIZED,
84 IMMUTABLE_IS_INITIALIZED_HARMONY,
85 IMMUTABLE_CHECK_INITIALIZED_HARMONY,
67 MISSING_BINDING 86 MISSING_BINDING
68 }; 87 };
69 88
70 89
71 // Heap-allocated activation contexts. 90 // Heap-allocated activation contexts.
72 // 91 //
73 // Contexts are implemented as FixedArray objects; the Context 92 // Contexts are implemented as FixedArray objects; the Context
74 // class is a convenience interface casted on a FixedArray object. 93 // class is a convenience interface casted on a FixedArray object.
75 // 94 //
76 // Note: Context must have no virtual functions and Context objects 95 // Note: Context must have no virtual functions and Context objects
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 #ifdef DEBUG 430 #ifdef DEBUG
412 // Bootstrapping-aware type checks. 431 // Bootstrapping-aware type checks.
413 static bool IsBootstrappingOrContext(Object* object); 432 static bool IsBootstrappingOrContext(Object* object);
414 static bool IsBootstrappingOrGlobalObject(Object* object); 433 static bool IsBootstrappingOrGlobalObject(Object* object);
415 #endif 434 #endif
416 }; 435 };
417 436
418 } } // namespace v8::internal 437 } } // namespace v8::internal
419 438
420 #endif // V8_CONTEXTS_H_ 439 #endif // V8_CONTEXTS_H_
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/contexts.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698