| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1795 // global scope. | 1795 // global scope. |
| 1796 var = declaration_scope->is_global_scope() | 1796 var = declaration_scope->is_global_scope() |
| 1797 ? declaration_scope->Lookup(name) | 1797 ? declaration_scope->Lookup(name) |
| 1798 : declaration_scope->LocalLookup(name); | 1798 : declaration_scope->LocalLookup(name); |
| 1799 if (var == NULL) { | 1799 if (var == NULL) { |
| 1800 // Declare the name. | 1800 // Declare the name. |
| 1801 var = declaration_scope->DeclareLocal( | 1801 var = declaration_scope->DeclareLocal( |
| 1802 name, mode, declaration->initialization(), proxy->interface()); | 1802 name, mode, declaration->initialization(), proxy->interface()); |
| 1803 } else if ((mode != VAR || var->mode() != VAR) && | 1803 } else if ((mode != VAR || var->mode() != VAR) && |
| 1804 (!declaration_scope->is_global_scope() || | 1804 (!declaration_scope->is_global_scope() || |
| 1805 (mode != VAR && mode != CONST) || | 1805 IsLexicalVariableMode(mode) || |
| 1806 (var->mode() != VAR && var->mode() != CONST))) { | 1806 IsLexicalVariableMode(var->mode()))) { |
| 1807 // The name was declared in this scope before; check for conflicting | 1807 // The name was declared in this scope before; check for conflicting |
| 1808 // re-declarations. We have a conflict if either of the declarations is | 1808 // re-declarations. We have a conflict if either of the declarations is |
| 1809 // not a var (in the global scope, we also have to ignore legacy const for | 1809 // not a var (in the global scope, we also have to ignore legacy const for |
| 1810 // compatibility). There is similar code in runtime.cc in the Declare | 1810 // compatibility). There is similar code in runtime.cc in the Declare |
| 1811 // functions. The function CheckNonConflictingScope checks for conflicting | 1811 // functions. The function CheckNonConflictingScope checks for conflicting |
| 1812 // var and let bindings from different scopes whereas this is a check for | 1812 // var and let bindings from different scopes whereas this is a check for |
| 1813 // conflicting declarations within the same scope. This check also covers | 1813 // conflicting declarations within the same scope. This check also covers |
| 1814 // the special case | 1814 // the special case |
| 1815 // | 1815 // |
| 1816 // function () { let x; { var x; } } | 1816 // function () { let x; { var x; } } |
| 1817 // | 1817 // |
| 1818 // because the var declaration is hoisted to the function scope where 'x' | 1818 // because the var declaration is hoisted to the function scope where 'x' |
| 1819 // is already bound. | 1819 // is already bound. |
| 1820 // We only have vars, consts and lets in declarations. | 1820 ASSERT(IsDeclaredVariableMode(var->mode())); |
| 1821 ASSERT(var->mode() == VAR || | |
| 1822 var->mode() == CONST || | |
| 1823 var->mode() == CONST_HARMONY || | |
| 1824 var->mode() == LET); | |
| 1825 if (is_extended_mode()) { | 1821 if (is_extended_mode()) { |
| 1826 // In harmony mode we treat re-declarations as early errors. See | 1822 // In harmony mode we treat re-declarations as early errors. See |
| 1827 // ES5 16 for a definition of early errors. | 1823 // ES5 16 for a definition of early errors. |
| 1828 SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS); | 1824 SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS); |
| 1829 const char* elms[2] = { "Variable", *c_string }; | 1825 const char* elms[2] = { "Variable", *c_string }; |
| 1830 Vector<const char*> args(elms, 2); | 1826 Vector<const char*> args(elms, 2); |
| 1831 ReportMessage("redeclaration", args); | 1827 ReportMessage("redeclaration", args); |
| 1832 *ok = false; | 1828 *ok = false; |
| 1833 return; | 1829 return; |
| 1834 } | 1830 } |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2334 // | 2330 // |
| 2335 // Executing the variable declaration statement will always | 2331 // Executing the variable declaration statement will always |
| 2336 // guarantee to give the global object a "local" variable; a | 2332 // guarantee to give the global object a "local" variable; a |
| 2337 // variable defined in the global object and not in any | 2333 // variable defined in the global object and not in any |
| 2338 // prototype. This way, global variable declarations can shadow | 2334 // prototype. This way, global variable declarations can shadow |
| 2339 // properties in the prototype chain, but only after the variable | 2335 // properties in the prototype chain, but only after the variable |
| 2340 // declaration statement has been executed. This is important in | 2336 // declaration statement has been executed. This is important in |
| 2341 // browsers where the global object (window) has lots of | 2337 // browsers where the global object (window) has lots of |
| 2342 // properties defined in prototype objects. | 2338 // properties defined in prototype objects. |
| 2343 if (initialization_scope->is_global_scope() && | 2339 if (initialization_scope->is_global_scope() && |
| 2344 mode != LET && mode != CONST_HARMONY) { | 2340 !IsLexicalVariableMode(mode)) { |
| 2345 // Compute the arguments for the runtime call. | 2341 // Compute the arguments for the runtime call. |
| 2346 ZoneList<Expression*>* arguments = | 2342 ZoneList<Expression*>* arguments = |
| 2347 new(zone()) ZoneList<Expression*>(3, zone()); | 2343 new(zone()) ZoneList<Expression*>(3, zone()); |
| 2348 // We have at least 1 parameter. | 2344 // We have at least 1 parameter. |
| 2349 arguments->Add(factory()->NewLiteral(name), zone()); | 2345 arguments->Add(factory()->NewLiteral(name), zone()); |
| 2350 CallRuntime* initialize; | 2346 CallRuntime* initialize; |
| 2351 | 2347 |
| 2352 if (is_const) { | 2348 if (is_const) { |
| 2353 arguments->Add(value, zone()); | 2349 arguments->Add(value, zone()); |
| 2354 value = NULL; // zap the value to avoid the unnecessary assignment | 2350 value = NULL; // zap the value to avoid the unnecessary assignment |
| (...skipping 3753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6108 ASSERT(info->isolate()->has_pending_exception()); | 6104 ASSERT(info->isolate()->has_pending_exception()); |
| 6109 } else { | 6105 } else { |
| 6110 result = parser.ParseProgram(); | 6106 result = parser.ParseProgram(); |
| 6111 } | 6107 } |
| 6112 } | 6108 } |
| 6113 info->SetFunction(result); | 6109 info->SetFunction(result); |
| 6114 return (result != NULL); | 6110 return (result != NULL); |
| 6115 } | 6111 } |
| 6116 | 6112 |
| 6117 } } // namespace v8::internal | 6113 } } // namespace v8::internal |
| OLD | NEW |