OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 <stdlib.h> | 5 #include <stdlib.h> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 2213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2224 // exists (based on the number of arguments). | 2224 // exists (based on the number of arguments). |
2225 RUNTIME_ASSERT(args.length() == 3); | 2225 RUNTIME_ASSERT(args.length() == 3); |
2226 | 2226 |
2227 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 2227 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
2228 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 1); | 2228 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 1); |
2229 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 2229 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
2230 | 2230 |
2231 Handle<GlobalObject> global(isolate->context()->global_object()); | 2231 Handle<GlobalObject> global(isolate->context()->global_object()); |
2232 Handle<Object> result; | 2232 Handle<Object> result; |
2233 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2233 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
2234 isolate, result, | 2234 isolate, result, Object::SetProperty(global, name, value, strict_mode)); |
2235 JSReceiver::SetProperty(global, name, value, strict_mode)); | |
2236 return *result; | 2235 return *result; |
2237 } | 2236 } |
2238 | 2237 |
2239 | 2238 |
2240 RUNTIME_FUNCTION(Runtime_InitializeConstGlobal) { | 2239 RUNTIME_FUNCTION(Runtime_InitializeConstGlobal) { |
2241 HandleScope handle_scope(isolate); | 2240 HandleScope handle_scope(isolate); |
2242 // All constants are declared with an initial value. The name | 2241 // All constants are declared with an initial value. The name |
2243 // of the constant is the first argument and the initial value | 2242 // of the constant is the first argument and the initial value |
2244 // is the second. | 2243 // is the second. |
2245 RUNTIME_ASSERT(args.length() == 2); | 2244 RUNTIME_ASSERT(args.length() == 2); |
(...skipping 2773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5019 | 5018 |
5020 if (object->IsJSProxy()) { | 5019 if (object->IsJSProxy()) { |
5021 Handle<Object> name_object; | 5020 Handle<Object> name_object; |
5022 if (key->IsSymbol()) { | 5021 if (key->IsSymbol()) { |
5023 name_object = key; | 5022 name_object = key; |
5024 } else { | 5023 } else { |
5025 ASSIGN_RETURN_ON_EXCEPTION( | 5024 ASSIGN_RETURN_ON_EXCEPTION( |
5026 isolate, name_object, Execution::ToString(isolate, key), Object); | 5025 isolate, name_object, Execution::ToString(isolate, key), Object); |
5027 } | 5026 } |
5028 Handle<Name> name = Handle<Name>::cast(name_object); | 5027 Handle<Name> name = Handle<Name>::cast(name_object); |
5029 return JSReceiver::SetProperty(Handle<JSProxy>::cast(object), name, value, | 5028 return Object::SetProperty(Handle<JSProxy>::cast(object), name, value, |
5030 strict_mode); | 5029 strict_mode); |
5031 } | 5030 } |
5032 | 5031 |
5033 // If the object isn't a JavaScript object, we ignore the store. | |
5034 if (!object->IsJSObject()) return value; | |
5035 | |
5036 Handle<JSObject> js_object = Handle<JSObject>::cast(object); | |
5037 | |
5038 // Check if the given key is an array index. | 5032 // Check if the given key is an array index. |
5039 uint32_t index; | 5033 uint32_t index; |
5040 if (key->ToArrayIndex(&index)) { | 5034 if (key->ToArrayIndex(&index)) { |
| 5035 // TODO(verwaest): Support non-JSObject receivers. |
| 5036 if (!object->IsJSObject()) return value; |
| 5037 Handle<JSObject> js_object = Handle<JSObject>::cast(object); |
| 5038 |
5041 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters | 5039 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters |
5042 // of a string using [] notation. We need to support this too in | 5040 // of a string using [] notation. We need to support this too in |
5043 // JavaScript. | 5041 // JavaScript. |
5044 // In the case of a String object we just need to redirect the assignment to | 5042 // In the case of a String object we just need to redirect the assignment to |
5045 // the underlying string if the index is in range. Since the underlying | 5043 // the underlying string if the index is in range. Since the underlying |
5046 // string does nothing with the assignment then we can ignore such | 5044 // string does nothing with the assignment then we can ignore such |
5047 // assignments. | 5045 // assignments. |
5048 if (js_object->IsStringObjectWithCharacterAt(index)) { | 5046 if (js_object->IsStringObjectWithCharacterAt(index)) { |
5049 return value; | 5047 return value; |
5050 } | 5048 } |
(...skipping 10 matching lines...) Expand all Loading... |
5061 MaybeHandle<Object> result = JSObject::SetElement( | 5059 MaybeHandle<Object> result = JSObject::SetElement( |
5062 js_object, index, value, NONE, strict_mode, true, SET_PROPERTY); | 5060 js_object, index, value, NONE, strict_mode, true, SET_PROPERTY); |
5063 JSObject::ValidateElements(js_object); | 5061 JSObject::ValidateElements(js_object); |
5064 | 5062 |
5065 return result.is_null() ? result : value; | 5063 return result.is_null() ? result : value; |
5066 } | 5064 } |
5067 | 5065 |
5068 if (key->IsName()) { | 5066 if (key->IsName()) { |
5069 Handle<Name> name = Handle<Name>::cast(key); | 5067 Handle<Name> name = Handle<Name>::cast(key); |
5070 if (name->AsArrayIndex(&index)) { | 5068 if (name->AsArrayIndex(&index)) { |
| 5069 // TODO(verwaest): Support non-JSObject receivers. |
| 5070 if (!object->IsJSObject()) return value; |
| 5071 Handle<JSObject> js_object = Handle<JSObject>::cast(object); |
5071 if (js_object->HasExternalArrayElements()) { | 5072 if (js_object->HasExternalArrayElements()) { |
5072 if (!value->IsNumber() && !value->IsUndefined()) { | 5073 if (!value->IsNumber() && !value->IsUndefined()) { |
5073 ASSIGN_RETURN_ON_EXCEPTION( | 5074 ASSIGN_RETURN_ON_EXCEPTION( |
5074 isolate, value, Execution::ToNumber(isolate, value), Object); | 5075 isolate, value, Execution::ToNumber(isolate, value), Object); |
5075 } | 5076 } |
5076 } | 5077 } |
5077 return JSObject::SetElement(js_object, index, value, NONE, strict_mode, | 5078 return JSObject::SetElement(js_object, index, value, NONE, strict_mode, |
5078 true, SET_PROPERTY); | 5079 true, SET_PROPERTY); |
5079 } else { | 5080 } else { |
5080 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); | 5081 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); |
5081 return JSReceiver::SetProperty(js_object, name, value, strict_mode); | 5082 return Object::SetProperty(object, name, value, strict_mode); |
5082 } | 5083 } |
5083 } | 5084 } |
5084 | 5085 |
5085 // Call-back into JavaScript to convert the key to a string. | 5086 // Call-back into JavaScript to convert the key to a string. |
5086 Handle<Object> converted; | 5087 Handle<Object> converted; |
5087 ASSIGN_RETURN_ON_EXCEPTION( | 5088 ASSIGN_RETURN_ON_EXCEPTION( |
5088 isolate, converted, Execution::ToString(isolate, key), Object); | 5089 isolate, converted, Execution::ToString(isolate, key), Object); |
5089 Handle<String> name = Handle<String>::cast(converted); | 5090 Handle<String> name = Handle<String>::cast(converted); |
5090 | 5091 |
5091 if (name->AsArrayIndex(&index)) { | 5092 if (name->AsArrayIndex(&index)) { |
| 5093 // TODO(verwaest): Support non-JSObject receivers. |
| 5094 if (!object->IsJSObject()) return value; |
| 5095 Handle<JSObject> js_object = Handle<JSObject>::cast(object); |
5092 return JSObject::SetElement(js_object, index, value, NONE, strict_mode, | 5096 return JSObject::SetElement(js_object, index, value, NONE, strict_mode, |
5093 true, SET_PROPERTY); | 5097 true, SET_PROPERTY); |
5094 } else { | |
5095 return JSReceiver::SetProperty(js_object, name, value, strict_mode); | |
5096 } | 5098 } |
| 5099 return Object::SetProperty(object, name, value, strict_mode); |
5097 } | 5100 } |
5098 | 5101 |
5099 | 5102 |
5100 MaybeHandle<Object> Runtime::DefineObjectProperty( | 5103 MaybeHandle<Object> Runtime::DefineObjectProperty( |
5101 Handle<JSObject> js_object, | 5104 Handle<JSObject> js_object, |
5102 Handle<Object> key, | 5105 Handle<Object> key, |
5103 Handle<Object> value, | 5106 Handle<Object> value, |
5104 PropertyAttributes attr, | 5107 PropertyAttributes attr, |
5105 JSReceiver::StoreFromKeyed store_from_keyed) { | 5108 JSReceiver::StoreFromKeyed store_from_keyed) { |
5106 Isolate* isolate = js_object->GetIsolate(); | 5109 Isolate* isolate = js_object->GetIsolate(); |
(...skipping 4153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9260 // If absent in strict mode: throw. | 9263 // If absent in strict mode: throw. |
9261 Handle<Object> error = isolate->factory()->NewReferenceError( | 9264 Handle<Object> error = isolate->factory()->NewReferenceError( |
9262 "not_defined", HandleVector(&name, 1)); | 9265 "not_defined", HandleVector(&name, 1)); |
9263 return isolate->Throw(*error); | 9266 return isolate->Throw(*error); |
9264 } else { | 9267 } else { |
9265 // If absent in sloppy mode: add the property to the global object. | 9268 // If absent in sloppy mode: add the property to the global object. |
9266 object = Handle<JSReceiver>(context->global_object()); | 9269 object = Handle<JSReceiver>(context->global_object()); |
9267 } | 9270 } |
9268 | 9271 |
9269 RETURN_FAILURE_ON_EXCEPTION( | 9272 RETURN_FAILURE_ON_EXCEPTION( |
9270 isolate, JSReceiver::SetProperty(object, name, value, strict_mode)); | 9273 isolate, Object::SetProperty(object, name, value, strict_mode)); |
9271 | 9274 |
9272 return *value; | 9275 return *value; |
9273 } | 9276 } |
9274 | 9277 |
9275 | 9278 |
9276 RUNTIME_FUNCTION(Runtime_Throw) { | 9279 RUNTIME_FUNCTION(Runtime_Throw) { |
9277 HandleScope scope(isolate); | 9280 HandleScope scope(isolate); |
9278 ASSERT(args.length() == 1); | 9281 ASSERT(args.length() == 1); |
9279 | 9282 |
9280 return isolate->Throw(args[0]); | 9283 return isolate->Throw(args[0]); |
(...skipping 5689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14970 } | 14973 } |
14971 return NULL; | 14974 return NULL; |
14972 } | 14975 } |
14973 | 14976 |
14974 | 14977 |
14975 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 14978 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
14976 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 14979 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
14977 } | 14980 } |
14978 | 14981 |
14979 } } // namespace v8::internal | 14982 } } // namespace v8::internal |
OLD | NEW |