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

Side by Side Diff: src/runtime/runtime-object.cc

Issue 894683003: Introduce LanguageMode, drop StrictMode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased (w/ conflicts) Created 5 years, 10 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
« no previous file with comments | « src/runtime/runtime-function.cc ('k') | src/runtime/runtime-scopes.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/bootstrapper.h" 8 #include "src/bootstrapper.h"
9 #include "src/debug.h" 9 #include "src/debug.h"
10 #include "src/runtime/runtime.h" 10 #include "src/runtime/runtime.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } else { 92 } else {
93 return Object::GetProperty(object, name); 93 return Object::GetProperty(object, name);
94 } 94 }
95 } 95 }
96 96
97 97
98 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, 98 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate,
99 Handle<Object> object, 99 Handle<Object> object,
100 Handle<Object> key, 100 Handle<Object> key,
101 Handle<Object> value, 101 Handle<Object> value,
102 StrictMode strict_mode) { 102 LanguageMode language_mode) {
103 if (object->IsUndefined() || object->IsNull()) { 103 if (object->IsUndefined() || object->IsNull()) {
104 Handle<Object> args[2] = {key, object}; 104 Handle<Object> args[2] = {key, object};
105 THROW_NEW_ERROR(isolate, NewTypeError("non_object_property_store", 105 THROW_NEW_ERROR(isolate, NewTypeError("non_object_property_store",
106 HandleVector(args, 2)), 106 HandleVector(args, 2)),
107 Object); 107 Object);
108 } 108 }
109 109
110 if (object->IsJSProxy()) { 110 if (object->IsJSProxy()) {
111 Handle<Object> name_object; 111 Handle<Object> name_object;
112 if (key->IsSymbol()) { 112 if (key->IsSymbol()) {
113 name_object = key; 113 name_object = key;
114 } else { 114 } else {
115 ASSIGN_RETURN_ON_EXCEPTION(isolate, name_object, 115 ASSIGN_RETURN_ON_EXCEPTION(isolate, name_object,
116 Execution::ToString(isolate, key), Object); 116 Execution::ToString(isolate, key), Object);
117 } 117 }
118 Handle<Name> name = Handle<Name>::cast(name_object); 118 Handle<Name> name = Handle<Name>::cast(name_object);
119 return Object::SetProperty(Handle<JSProxy>::cast(object), name, value, 119 return Object::SetProperty(Handle<JSProxy>::cast(object), name, value,
120 strict_mode); 120 language_mode);
121 } 121 }
122 122
123 // Check if the given key is an array index. 123 // Check if the given key is an array index.
124 uint32_t index; 124 uint32_t index;
125 if (key->ToArrayIndex(&index)) { 125 if (key->ToArrayIndex(&index)) {
126 // TODO(verwaest): Support non-JSObject receivers. 126 // TODO(verwaest): Support non-JSObject receivers.
127 if (!object->IsJSObject()) return value; 127 if (!object->IsJSObject()) return value;
128 Handle<JSObject> js_object = Handle<JSObject>::cast(object); 128 Handle<JSObject> js_object = Handle<JSObject>::cast(object);
129 129
130 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters 130 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters
(...skipping 10 matching lines...) Expand all
141 JSObject::ValidateElements(js_object); 141 JSObject::ValidateElements(js_object);
142 if (js_object->HasExternalArrayElements() || 142 if (js_object->HasExternalArrayElements() ||
143 js_object->HasFixedTypedArrayElements()) { 143 js_object->HasFixedTypedArrayElements()) {
144 if (!value->IsNumber() && !value->IsUndefined()) { 144 if (!value->IsNumber() && !value->IsUndefined()) {
145 ASSIGN_RETURN_ON_EXCEPTION(isolate, value, 145 ASSIGN_RETURN_ON_EXCEPTION(isolate, value,
146 Execution::ToNumber(isolate, value), Object); 146 Execution::ToNumber(isolate, value), Object);
147 } 147 }
148 } 148 }
149 149
150 MaybeHandle<Object> result = JSObject::SetElement( 150 MaybeHandle<Object> result = JSObject::SetElement(
151 js_object, index, value, NONE, strict_mode, true, SET_PROPERTY); 151 js_object, index, value, NONE, language_mode, true, SET_PROPERTY);
152 JSObject::ValidateElements(js_object); 152 JSObject::ValidateElements(js_object);
153 153
154 return result.is_null() ? result : value; 154 return result.is_null() ? result : value;
155 } 155 }
156 156
157 if (key->IsName()) { 157 if (key->IsName()) {
158 Handle<Name> name = Handle<Name>::cast(key); 158 Handle<Name> name = Handle<Name>::cast(key);
159 if (name->AsArrayIndex(&index)) { 159 if (name->AsArrayIndex(&index)) {
160 // TODO(verwaest): Support non-JSObject receivers. 160 // TODO(verwaest): Support non-JSObject receivers.
161 if (!object->IsJSObject()) return value; 161 if (!object->IsJSObject()) return value;
162 Handle<JSObject> js_object = Handle<JSObject>::cast(object); 162 Handle<JSObject> js_object = Handle<JSObject>::cast(object);
163 if (js_object->HasExternalArrayElements()) { 163 if (js_object->HasExternalArrayElements()) {
164 if (!value->IsNumber() && !value->IsUndefined()) { 164 if (!value->IsNumber() && !value->IsUndefined()) {
165 ASSIGN_RETURN_ON_EXCEPTION( 165 ASSIGN_RETURN_ON_EXCEPTION(
166 isolate, value, Execution::ToNumber(isolate, value), Object); 166 isolate, value, Execution::ToNumber(isolate, value), Object);
167 } 167 }
168 } 168 }
169 return JSObject::SetElement(js_object, index, value, NONE, strict_mode, 169 return JSObject::SetElement(js_object, index, value, NONE, language_mode,
170 true, SET_PROPERTY); 170 true, SET_PROPERTY);
171 } else { 171 } else {
172 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); 172 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name));
173 return Object::SetProperty(object, name, value, strict_mode); 173 return Object::SetProperty(object, name, value, language_mode);
174 } 174 }
175 } 175 }
176 176
177 // Call-back into JavaScript to convert the key to a string. 177 // Call-back into JavaScript to convert the key to a string.
178 Handle<Object> converted; 178 Handle<Object> converted;
179 ASSIGN_RETURN_ON_EXCEPTION(isolate, converted, 179 ASSIGN_RETURN_ON_EXCEPTION(isolate, converted,
180 Execution::ToString(isolate, key), Object); 180 Execution::ToString(isolate, key), Object);
181 Handle<String> name = Handle<String>::cast(converted); 181 Handle<String> name = Handle<String>::cast(converted);
182 182
183 if (name->AsArrayIndex(&index)) { 183 if (name->AsArrayIndex(&index)) {
184 // TODO(verwaest): Support non-JSObject receivers. 184 // TODO(verwaest): Support non-JSObject receivers.
185 if (!object->IsJSObject()) return value; 185 if (!object->IsJSObject()) return value;
186 Handle<JSObject> js_object = Handle<JSObject>::cast(object); 186 Handle<JSObject> js_object = Handle<JSObject>::cast(object);
187 return JSObject::SetElement(js_object, index, value, NONE, strict_mode, 187 return JSObject::SetElement(js_object, index, value, NONE, language_mode,
188 true, SET_PROPERTY); 188 true, SET_PROPERTY);
189 } 189 }
190 return Object::SetProperty(object, name, value, strict_mode); 190 return Object::SetProperty(object, name, value, language_mode);
191 } 191 }
192 192
193 193
194 MaybeHandle<Object> Runtime::DefineObjectProperty(Handle<JSObject> js_object, 194 MaybeHandle<Object> Runtime::DefineObjectProperty(Handle<JSObject> js_object,
195 Handle<Object> key, 195 Handle<Object> key,
196 Handle<Object> value, 196 Handle<Object> value,
197 PropertyAttributes attr) { 197 PropertyAttributes attr) {
198 Isolate* isolate = js_object->GetIsolate(); 198 Isolate* isolate = js_object->GetIsolate();
199 // Check if the given key is an array index. 199 // Check if the given key is an array index.
200 uint32_t index; 200 uint32_t index;
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 } 688 }
689 689
690 690
691 RUNTIME_FUNCTION(Runtime_SetProperty) { 691 RUNTIME_FUNCTION(Runtime_SetProperty) {
692 HandleScope scope(isolate); 692 HandleScope scope(isolate);
693 RUNTIME_ASSERT(args.length() == 4); 693 RUNTIME_ASSERT(args.length() == 4);
694 694
695 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); 695 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
696 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 696 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
697 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 697 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
698 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode_arg, 3); 698 CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode_arg, 3);
699 StrictMode strict_mode = strict_mode_arg; 699 LanguageMode language_mode = language_mode_arg;
700 700
701 Handle<Object> result; 701 Handle<Object> result;
702 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 702 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
703 isolate, result, 703 isolate, result,
704 Runtime::SetObjectProperty(isolate, object, key, value, strict_mode)); 704 Runtime::SetObjectProperty(isolate, object, key, value, language_mode));
705 return *result; 705 return *result;
706 } 706 }
707 707
708 708
709 // Adds an element to an array. 709 // Adds an element to an array.
710 // This is used to create an indexed data property into an array. 710 // This is used to create an indexed data property into an array.
711 RUNTIME_FUNCTION(Runtime_AddElement) { 711 RUNTIME_FUNCTION(Runtime_AddElement) {
712 HandleScope scope(isolate); 712 HandleScope scope(isolate);
713 RUNTIME_ASSERT(args.length() == 4); 713 RUNTIME_ASSERT(args.length() == 4);
714 714
(...skipping 16 matching lines...) Expand all
731 SLOPPY, false, DEFINE_PROPERTY)); 731 SLOPPY, false, DEFINE_PROPERTY));
732 return *result; 732 return *result;
733 } 733 }
734 734
735 735
736 RUNTIME_FUNCTION(Runtime_DeleteProperty) { 736 RUNTIME_FUNCTION(Runtime_DeleteProperty) {
737 HandleScope scope(isolate); 737 HandleScope scope(isolate);
738 DCHECK(args.length() == 3); 738 DCHECK(args.length() == 3);
739 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); 739 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0);
740 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); 740 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1);
741 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 2); 741 CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode, 2);
742 Handle<Object> result; 742 Handle<Object> result;
743 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 743 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
744 isolate, result, JSReceiver::DeleteProperty(object, key, strict_mode)); 744 isolate, result, JSReceiver::DeleteProperty(object, key, language_mode));
745 return *result; 745 return *result;
746 } 746 }
747 747
748 748
749 static Object* HasOwnPropertyImplementation(Isolate* isolate, 749 static Object* HasOwnPropertyImplementation(Isolate* isolate,
750 Handle<JSObject> object, 750 Handle<JSObject> object,
751 Handle<Name> key) { 751 Handle<Name> key) {
752 Maybe<bool> maybe = JSReceiver::HasOwnProperty(object, key); 752 Maybe<bool> maybe = JSReceiver::HasOwnProperty(object, key);
753 if (!maybe.has_value) return isolate->heap()->exception(); 753 if (!maybe.has_value) return isolate->heap()->exception();
754 if (maybe.value) return isolate->heap()->true_value(); 754 if (maybe.value) return isolate->heap()->true_value();
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 CONVERT_ARG_HANDLE_CHECKED(JSFunction, setter, 2); 1610 CONVERT_ARG_HANDLE_CHECKED(JSFunction, setter, 2);
1611 1611
1612 RETURN_FAILURE_ON_EXCEPTION( 1612 RETURN_FAILURE_ON_EXCEPTION(
1613 isolate, 1613 isolate,
1614 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), 1614 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(),
1615 setter, NONE)); 1615 setter, NONE));
1616 return isolate->heap()->undefined_value(); 1616 return isolate->heap()->undefined_value();
1617 } 1617 }
1618 } 1618 }
1619 } // namespace v8::internal 1619 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime/runtime-function.cc ('k') | src/runtime/runtime-scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698