OLD | NEW |
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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 | 871 |
872 void Scope::AllocateHeapSlot(Variable* var) { | 872 void Scope::AllocateHeapSlot(Variable* var) { |
873 var->set_rewrite(new Slot(var, Slot::CONTEXT, num_heap_slots_++)); | 873 var->set_rewrite(new Slot(var, Slot::CONTEXT, num_heap_slots_++)); |
874 } | 874 } |
875 | 875 |
876 | 876 |
877 void Scope::AllocateParameterLocals() { | 877 void Scope::AllocateParameterLocals() { |
878 ASSERT(is_function_scope()); | 878 ASSERT(is_function_scope()); |
879 Variable* arguments = LocalLookup(Factory::arguments_symbol()); | 879 Variable* arguments = LocalLookup(Factory::arguments_symbol()); |
880 ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly | 880 ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly |
| 881 |
| 882 // Parameters are rewritten to arguments[i] if 'arguments' is used in |
| 883 // a non-strict mode function. Strict mode code doesn't alias arguments. |
| 884 bool rewrite_parameters = false; |
| 885 |
881 if (MustAllocate(arguments) && !HasArgumentsParameter()) { | 886 if (MustAllocate(arguments) && !HasArgumentsParameter()) { |
882 // 'arguments' is used. Unless there is also a parameter called | 887 // 'arguments' is used. Unless there is also a parameter called |
883 // 'arguments', we must be conservative and access all parameters via | 888 // 'arguments', we must be conservative and access all parameters via |
884 // the arguments object: The i'th parameter is rewritten into | 889 // the arguments object: The i'th parameter is rewritten into |
885 // '.arguments[i]' (*). If we have a parameter named 'arguments', a | 890 // '.arguments[i]' (*). If we have a parameter named 'arguments', a |
886 // (new) value is always assigned to it via the function | 891 // (new) value is always assigned to it via the function |
887 // invocation. Then 'arguments' denotes that specific parameter value | 892 // invocation. Then 'arguments' denotes that specific parameter value |
888 // and cannot be used to access the parameters, which is why we don't | 893 // and cannot be used to access the parameters, which is why we don't |
889 // need to rewrite in that case. | 894 // need to rewrite in that case. |
890 // | 895 // |
(...skipping 11 matching lines...) Expand all Loading... |
902 // allocated. All parameters are rewritten into property accesses via | 907 // allocated. All parameters are rewritten into property accesses via |
903 // the '.arguments' variable. Thus, any changes to properties of | 908 // the '.arguments' variable. Thus, any changes to properties of |
904 // 'arguments' are reflected in the variables and vice versa. If the | 909 // 'arguments' are reflected in the variables and vice versa. If the |
905 // 'arguments' variable is changed, '.arguments' still points to the | 910 // 'arguments' variable is changed, '.arguments' still points to the |
906 // correct arguments object and the rewrites still work. | 911 // correct arguments object and the rewrites still work. |
907 | 912 |
908 // We are using 'arguments'. Tell the code generator that is needs to | 913 // We are using 'arguments'. Tell the code generator that is needs to |
909 // allocate the arguments object by setting 'arguments_'. | 914 // allocate the arguments object by setting 'arguments_'. |
910 arguments_ = arguments; | 915 arguments_ = arguments; |
911 | 916 |
| 917 // In strict mode 'arguments' does not alias formal parameters. |
| 918 // Therefore in strict mode we allocate parameters as if 'arguments' |
| 919 // were not used. |
| 920 rewrite_parameters = !is_strict_mode(); |
| 921 } |
| 922 |
| 923 if (rewrite_parameters) { |
912 // We also need the '.arguments' shadow variable. Declare it and create | 924 // We also need the '.arguments' shadow variable. Declare it and create |
913 // and bind the corresponding proxy. It's ok to declare it only now | 925 // and bind the corresponding proxy. It's ok to declare it only now |
914 // because it's a local variable that is allocated after the parameters | 926 // because it's a local variable that is allocated after the parameters |
915 // have been allocated. | 927 // have been allocated. |
916 // | 928 // |
917 // Note: This is "almost" at temporary variable but we cannot use | 929 // Note: This is "almost" at temporary variable but we cannot use |
918 // NewTemporary() because the mode needs to be INTERNAL since this | 930 // NewTemporary() because the mode needs to be INTERNAL since this |
919 // variable may be allocated in the heap-allocated context (temporaries | 931 // variable may be allocated in the heap-allocated context (temporaries |
920 // are never allocated in the context). | 932 // are never allocated in the context). |
921 arguments_shadow_ = new Variable(this, | 933 arguments_shadow_ = new Variable(this, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && | 1066 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && |
1055 !must_have_local_context) { | 1067 !must_have_local_context) { |
1056 num_heap_slots_ = 0; | 1068 num_heap_slots_ = 0; |
1057 } | 1069 } |
1058 | 1070 |
1059 // Allocation done. | 1071 // Allocation done. |
1060 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 1072 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
1061 } | 1073 } |
1062 | 1074 |
1063 } } // namespace v8::internal | 1075 } } // namespace v8::internal |
OLD | NEW |