| OLD | NEW |
| 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 1755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1766 // which the variable or constant is declared. Only function variables have | 1766 // which the variable or constant is declared. Only function variables have |
| 1767 // an initial value in the declaration (because they are initialized upon | 1767 // an initial value in the declaration (because they are initialized upon |
| 1768 // entering the function). | 1768 // entering the function). |
| 1769 // | 1769 // |
| 1770 // If we have a const declaration, in an inner scope, the proxy is always | 1770 // If we have a const declaration, in an inner scope, the proxy is always |
| 1771 // bound to the declared variable (independent of possibly surrounding with | 1771 // bound to the declared variable (independent of possibly surrounding with |
| 1772 // statements). | 1772 // statements). |
| 1773 // For let/const declarations in harmony mode, we can also immediately | 1773 // For let/const declarations in harmony mode, we can also immediately |
| 1774 // pre-resolve the proxy because it resides in the same scope as the | 1774 // pre-resolve the proxy because it resides in the same scope as the |
| 1775 // declaration. | 1775 // declaration. |
| 1776 Declare(name, mode, NULL, mode != VAR, CHECK_OK); | 1776 VariableProxy* proxy = Declare(name, mode, NULL, mode != VAR, CHECK_OK); |
| 1777 nvars++; | 1777 nvars++; |
| 1778 if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) { | 1778 if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) { |
| 1779 ReportMessageAt(scanner().location(), "too_many_variables", | 1779 ReportMessageAt(scanner().location(), "too_many_variables", |
| 1780 Vector<const char*>::empty()); | 1780 Vector<const char*>::empty()); |
| 1781 *ok = false; | 1781 *ok = false; |
| 1782 return NULL; | 1782 return NULL; |
| 1783 } | 1783 } |
| 1784 | 1784 |
| 1785 // Parse initialization expression if present and/or needed. A | 1785 // Parse initialization expression if present and/or needed. A |
| 1786 // declaration of the form: | 1786 // declaration of the form: |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1821 if (fni_ != NULL && | 1821 if (fni_ != NULL && |
| 1822 value->AsCall() == NULL && | 1822 value->AsCall() == NULL && |
| 1823 value->AsCallNew() == NULL) { | 1823 value->AsCallNew() == NULL) { |
| 1824 fni_->Infer(); | 1824 fni_->Infer(); |
| 1825 } else { | 1825 } else { |
| 1826 fni_->RemoveLastFunction(); | 1826 fni_->RemoveLastFunction(); |
| 1827 } | 1827 } |
| 1828 if (decl_props != NULL) *decl_props = kHasInitializers; | 1828 if (decl_props != NULL) *decl_props = kHasInitializers; |
| 1829 } | 1829 } |
| 1830 | 1830 |
| 1831 // Record the end position of the initializer. |
| 1832 if (proxy->var() != NULL) { |
| 1833 proxy->var()->set_initializer_position(scanner().location().end_pos); |
| 1834 } |
| 1835 |
| 1831 // Make sure that 'const x' and 'let x' initialize 'x' to undefined. | 1836 // Make sure that 'const x' and 'let x' initialize 'x' to undefined. |
| 1832 if (value == NULL && needs_init) { | 1837 if (value == NULL && needs_init) { |
| 1833 value = GetLiteralUndefined(); | 1838 value = GetLiteralUndefined(); |
| 1834 } | 1839 } |
| 1835 | 1840 |
| 1836 // Global variable declarations must be compiled in a specific | 1841 // Global variable declarations must be compiled in a specific |
| 1837 // way. When the script containing the global variable declaration | 1842 // way. When the script containing the global variable declaration |
| 1838 // is entered, the global variable must be declared, so that if it | 1843 // is entered, the global variable must be declared, so that if it |
| 1839 // doesn't exist (not even in a prototype of the global object) it | 1844 // doesn't exist (not even in a prototype of the global object) it |
| 1840 // gets created with an initial undefined value. This is handled | 1845 // gets created with an initial undefined value. This is handled |
| (...skipping 3577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5418 result = parser.ParseProgram(source, | 5423 result = parser.ParseProgram(source, |
| 5419 info->is_global(), | 5424 info->is_global(), |
| 5420 info->strict_mode_flag()); | 5425 info->strict_mode_flag()); |
| 5421 } | 5426 } |
| 5422 } | 5427 } |
| 5423 info->SetFunction(result); | 5428 info->SetFunction(result); |
| 5424 return (result != NULL); | 5429 return (result != NULL); |
| 5425 } | 5430 } |
| 5426 | 5431 |
| 5427 } } // namespace v8::internal | 5432 } } // namespace v8::internal |
| OLD | NEW |