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

Side by Side Diff: src/parser.cc

Issue 6576024: (early draft) Strict mode - throw exception on assignment to read only property. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Assign to read only property in strict mode. Created 9 years, 9 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/objects-inl.h ('k') | src/runtime.h » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 1616 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 // guarantee to give the global object a "local" variable; a 1627 // guarantee to give the global object a "local" variable; a
1628 // variable defined in the global object and not in any 1628 // variable defined in the global object and not in any
1629 // prototype. This way, global variable declarations can shadow 1629 // prototype. This way, global variable declarations can shadow
1630 // properties in the prototype chain, but only after the variable 1630 // properties in the prototype chain, but only after the variable
1631 // declaration statement has been executed. This is important in 1631 // declaration statement has been executed. This is important in
1632 // browsers where the global object (window) has lots of 1632 // browsers where the global object (window) has lots of
1633 // properties defined in prototype objects. 1633 // properties defined in prototype objects.
1634 1634
1635 if (top_scope_->is_global_scope()) { 1635 if (top_scope_->is_global_scope()) {
1636 // Compute the arguments for the runtime call. 1636 // Compute the arguments for the runtime call.
1637 ZoneList<Expression*>* arguments = new ZoneList<Expression*>(2); 1637 ZoneList<Expression*>* arguments = new ZoneList<Expression*>(3);
1638 // Be careful not to assign a value to the global variable if
1639 // we're in a with. The initialization value should not
1640 // necessarily be stored in the global object in that case,
1641 // which is why we need to generate a separate assignment node.
1642 arguments->Add(new Literal(name)); // we have at least 1 parameter 1638 arguments->Add(new Literal(name)); // we have at least 1 parameter
1643 if (is_const || (value != NULL && !inside_with())) { 1639 CallRuntime* initialize;
1640
1641 if (is_const) {
1644 arguments->Add(value); 1642 arguments->Add(value);
1645 value = NULL; // zap the value to avoid the unnecessary assignment 1643 value = NULL; // zap the value to avoid the unnecessary assignment
1644
1645 // Construct the call to Runtime_InitializeConstGlobal
1646 // and add it to the initialization statement block.
1647 // Note that the function does different things depending on
1648 // the number of arguments (1 or 2).
1649 initialize =
1650 new CallRuntime(
1651 Factory::InitializeConstGlobal_symbol(),
1652 Runtime::FunctionForId(Runtime::kInitializeConstGlobal),
1653 arguments);
1654 } else {
1655 // Add strict mode.
1656 // We may want to pass singleton to avoid Literal allocations.
1657 arguments->Add(NewNumberLiteral(
1658 temp_scope_->StrictMode() ? kStrictMode : kNonStrictMode));
1659
1660 // Be careful not to assign a value to the global variable if
1661 // we're in a with. The initialization value should not
1662 // necessarily be stored in the global object in that case,
1663 // which is why we need to generate a separate assignment node.
1664 if (value != NULL && !inside_with()) {
1665 arguments->Add(value);
1666 value = NULL; // zap the value to avoid the unnecessary assignment
1667 }
1668
1669 // Construct the call to Runtime_InitializeVarGlobal
1670 // and add it to the initialization statement block.
1671 // Note that the function does different things depending on
1672 // the number of arguments (2 or 3).
1673 initialize =
1674 new CallRuntime(
1675 Factory::InitializeVarGlobal_symbol(),
1676 Runtime::FunctionForId(Runtime::kInitializeVarGlobal),
1677 arguments);
1646 } 1678 }
1647 // Construct the call to Runtime::DeclareGlobal{Variable,Const}Locally 1679
1648 // and add it to the initialization statement block. Note that
1649 // this function does different things depending on if we have
1650 // 1 or 2 parameters.
1651 CallRuntime* initialize;
1652 if (is_const) {
1653 initialize =
1654 new CallRuntime(
1655 Factory::InitializeConstGlobal_symbol(),
1656 Runtime::FunctionForId(Runtime::kInitializeConstGlobal),
1657 arguments);
1658 } else {
1659 initialize =
1660 new CallRuntime(
1661 Factory::InitializeVarGlobal_symbol(),
1662 Runtime::FunctionForId(Runtime::kInitializeVarGlobal),
1663 arguments);
1664 }
1665 block->AddStatement(new ExpressionStatement(initialize)); 1680 block->AddStatement(new ExpressionStatement(initialize));
1666 } 1681 }
1667 1682
1668 // Add an assignment node to the initialization statement block if 1683 // Add an assignment node to the initialization statement block if
1669 // we still have a pending initialization value. We must distinguish 1684 // we still have a pending initialization value. We must distinguish
1670 // between variables and constants: Variable initializations are simply 1685 // between variables and constants: Variable initializations are simply
1671 // assignments (with all the consequences if they are inside a 'with' 1686 // assignments (with all the consequences if they are inside a 'with'
1672 // statement - they may change a 'with' object property). Constant 1687 // statement - they may change a 'with' object property). Constant
1673 // initializations always assign to the declared constant which is 1688 // initializations always assign to the declared constant which is
1674 // always at the function scope level. This is only relevant for 1689 // always at the function scope level. This is only relevant for
(...skipping 3439 matching lines...) Expand 10 before | Expand all | Expand 10 after
5114 info->is_global(), 5129 info->is_global(),
5115 info->StrictMode()); 5130 info->StrictMode());
5116 } 5131 }
5117 } 5132 }
5118 5133
5119 info->SetFunction(result); 5134 info->SetFunction(result);
5120 return (result != NULL); 5135 return (result != NULL);
5121 } 5136 }
5122 5137
5123 } } // namespace v8::internal 5138 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698