| 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 // The value contains the constant_properties of a | 260 // The value contains the constant_properties of a |
| 261 // simple object or array literal. | 261 // simple object or array literal. |
| 262 Handle<FixedArray> array = Handle<FixedArray>::cast(value); | 262 Handle<FixedArray> array = Handle<FixedArray>::cast(value); |
| 263 ASSIGN_RETURN_ON_EXCEPTION( | 263 ASSIGN_RETURN_ON_EXCEPTION( |
| 264 isolate, value, | 264 isolate, value, |
| 265 CreateLiteralBoilerplate(isolate, literals, array), | 265 CreateLiteralBoilerplate(isolate, literals, array), |
| 266 Object); | 266 Object); |
| 267 } | 267 } |
| 268 MaybeHandle<Object> maybe_result; | 268 MaybeHandle<Object> maybe_result; |
| 269 uint32_t element_index = 0; | 269 uint32_t element_index = 0; |
| 270 StoreMode mode = value->IsJSObject() ? FORCE_FIELD : ALLOW_AS_CONSTANT; | |
| 271 if (key->IsInternalizedString()) { | 270 if (key->IsInternalizedString()) { |
| 272 if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) { | 271 if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) { |
| 273 // Array index as string (uint32). | 272 // Array index as string (uint32). |
| 274 if (value->IsUninitialized()) value = handle(Smi::FromInt(0), isolate); | 273 if (value->IsUninitialized()) value = handle(Smi::FromInt(0), isolate); |
| 275 maybe_result = | 274 maybe_result = |
| 276 JSObject::SetOwnElement(boilerplate, element_index, value, SLOPPY); | 275 JSObject::SetOwnElement(boilerplate, element_index, value, SLOPPY); |
| 277 } else { | 276 } else { |
| 278 Handle<String> name(String::cast(*key)); | 277 Handle<String> name(String::cast(*key)); |
| 279 ASSERT(!name->AsArrayIndex(&element_index)); | 278 ASSERT(!name->AsArrayIndex(&element_index)); |
| 280 maybe_result = JSObject::SetOwnPropertyIgnoreAttributes( | 279 maybe_result = JSObject::SetOwnPropertyIgnoreAttributes( |
| 281 boilerplate, name, value, NONE, mode); | 280 boilerplate, name, value, NONE); |
| 282 } | 281 } |
| 283 } else if (key->ToArrayIndex(&element_index)) { | 282 } else if (key->ToArrayIndex(&element_index)) { |
| 284 // Array index (uint32). | 283 // Array index (uint32). |
| 285 if (value->IsUninitialized()) value = handle(Smi::FromInt(0), isolate); | 284 if (value->IsUninitialized()) value = handle(Smi::FromInt(0), isolate); |
| 286 maybe_result = | 285 maybe_result = |
| 287 JSObject::SetOwnElement(boilerplate, element_index, value, SLOPPY); | 286 JSObject::SetOwnElement(boilerplate, element_index, value, SLOPPY); |
| 288 } else { | 287 } else { |
| 289 // Non-uint32 number. | 288 // Non-uint32 number. |
| 290 ASSERT(key->IsNumber()); | 289 ASSERT(key->IsNumber()); |
| 291 double num = key->Number(); | 290 double num = key->Number(); |
| 292 char arr[100]; | 291 char arr[100]; |
| 293 Vector<char> buffer(arr, ARRAY_SIZE(arr)); | 292 Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
| 294 const char* str = DoubleToCString(num, buffer); | 293 const char* str = DoubleToCString(num, buffer); |
| 295 Handle<String> name = isolate->factory()->NewStringFromAsciiChecked(str); | 294 Handle<String> name = isolate->factory()->NewStringFromAsciiChecked(str); |
| 296 maybe_result = JSObject::SetOwnPropertyIgnoreAttributes( | 295 maybe_result = JSObject::SetOwnPropertyIgnoreAttributes(boilerplate, name, |
| 297 boilerplate, name, value, NONE, mode); | 296 value, NONE); |
| 298 } | 297 } |
| 299 // If setting the property on the boilerplate throws an | 298 // If setting the property on the boilerplate throws an |
| 300 // exception, the exception is converted to an empty handle in | 299 // exception, the exception is converted to an empty handle in |
| 301 // the handle based operations. In that case, we need to | 300 // the handle based operations. In that case, we need to |
| 302 // convert back to an exception. | 301 // convert back to an exception. |
| 303 RETURN_ON_EXCEPTION(isolate, maybe_result, Object); | 302 RETURN_ON_EXCEPTION(isolate, maybe_result, Object); |
| 304 } | 303 } |
| 305 | 304 |
| 306 // Transform to fast properties if necessary. For object literals with | 305 // Transform to fast properties if necessary. For object literals with |
| 307 // containing function literals we defer this operation until after all | 306 // containing function literals we defer this operation until after all |
| (...skipping 4664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4972 JSObject::NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0); | 4971 JSObject::NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0); |
| 4973 } | 4972 } |
| 4974 | 4973 |
| 4975 // Use IgnoreAttributes version since a readonly property may be | 4974 // Use IgnoreAttributes version since a readonly property may be |
| 4976 // overridden and SetProperty does not allow this. | 4975 // overridden and SetProperty does not allow this. |
| 4977 Handle<Object> result; | 4976 Handle<Object> result; |
| 4978 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 4977 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 4979 isolate, result, | 4978 isolate, result, |
| 4980 JSObject::SetOwnPropertyIgnoreAttributes( | 4979 JSObject::SetOwnPropertyIgnoreAttributes( |
| 4981 js_object, name, obj_value, attr, | 4980 js_object, name, obj_value, attr, |
| 4982 ALLOW_AS_CONSTANT, | |
| 4983 JSReceiver::PERFORM_EXTENSIBILITY_CHECK, | 4981 JSReceiver::PERFORM_EXTENSIBILITY_CHECK, |
| 4984 JSReceiver::MAY_BE_STORE_FROM_KEYED, | 4982 JSReceiver::MAY_BE_STORE_FROM_KEYED, |
| 4985 JSObject::DONT_FORCE_FIELD)); | 4983 JSObject::DONT_FORCE_FIELD)); |
| 4986 return *result; | 4984 return *result; |
| 4987 } | 4985 } |
| 4988 | 4986 |
| 4989 Handle<Object> result; | 4987 Handle<Object> result; |
| 4990 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 4988 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 4991 isolate, result, | 4989 isolate, result, |
| 4992 Runtime::DefineObjectProperty( | 4990 Runtime::DefineObjectProperty( |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5125 } | 5123 } |
| 5126 | 5124 |
| 5127 if (key->IsName()) { | 5125 if (key->IsName()) { |
| 5128 Handle<Name> name = Handle<Name>::cast(key); | 5126 Handle<Name> name = Handle<Name>::cast(key); |
| 5129 if (name->AsArrayIndex(&index)) { | 5127 if (name->AsArrayIndex(&index)) { |
| 5130 return JSObject::SetElement(js_object, index, value, attr, | 5128 return JSObject::SetElement(js_object, index, value, attr, |
| 5131 SLOPPY, false, DEFINE_PROPERTY); | 5129 SLOPPY, false, DEFINE_PROPERTY); |
| 5132 } else { | 5130 } else { |
| 5133 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); | 5131 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); |
| 5134 return JSObject::SetOwnPropertyIgnoreAttributes( | 5132 return JSObject::SetOwnPropertyIgnoreAttributes( |
| 5135 js_object, name, value, attr, ALLOW_AS_CONSTANT, | 5133 js_object, name, value, attr, JSReceiver::PERFORM_EXTENSIBILITY_CHECK, |
| 5136 JSReceiver::PERFORM_EXTENSIBILITY_CHECK, store_from_keyed); | 5134 store_from_keyed); |
| 5137 } | 5135 } |
| 5138 } | 5136 } |
| 5139 | 5137 |
| 5140 // Call-back into JavaScript to convert the key to a string. | 5138 // Call-back into JavaScript to convert the key to a string. |
| 5141 Handle<Object> converted; | 5139 Handle<Object> converted; |
| 5142 ASSIGN_RETURN_ON_EXCEPTION( | 5140 ASSIGN_RETURN_ON_EXCEPTION( |
| 5143 isolate, converted, Execution::ToString(isolate, key), Object); | 5141 isolate, converted, Execution::ToString(isolate, key), Object); |
| 5144 Handle<String> name = Handle<String>::cast(converted); | 5142 Handle<String> name = Handle<String>::cast(converted); |
| 5145 | 5143 |
| 5146 if (name->AsArrayIndex(&index)) { | 5144 if (name->AsArrayIndex(&index)) { |
| 5147 return JSObject::SetElement(js_object, index, value, attr, | 5145 return JSObject::SetElement(js_object, index, value, attr, |
| 5148 SLOPPY, false, DEFINE_PROPERTY); | 5146 SLOPPY, false, DEFINE_PROPERTY); |
| 5149 } else { | 5147 } else { |
| 5150 return JSObject::SetOwnPropertyIgnoreAttributes( | 5148 return JSObject::SetOwnPropertyIgnoreAttributes( |
| 5151 js_object, name, value, attr, ALLOW_AS_CONSTANT, | 5149 js_object, name, value, attr, JSReceiver::PERFORM_EXTENSIBILITY_CHECK, |
| 5152 JSReceiver::PERFORM_EXTENSIBILITY_CHECK, store_from_keyed); | 5150 store_from_keyed); |
| 5153 } | 5151 } |
| 5154 } | 5152 } |
| 5155 | 5153 |
| 5156 | 5154 |
| 5157 MaybeHandle<Object> Runtime::DeleteObjectProperty(Isolate* isolate, | 5155 MaybeHandle<Object> Runtime::DeleteObjectProperty(Isolate* isolate, |
| 5158 Handle<JSReceiver> receiver, | 5156 Handle<JSReceiver> receiver, |
| 5159 Handle<Object> key, | 5157 Handle<Object> key, |
| 5160 JSReceiver::DeleteMode mode) { | 5158 JSReceiver::DeleteMode mode) { |
| 5161 // Check if the given key is an array index. | 5159 // Check if the given key is an array index. |
| 5162 uint32_t index; | 5160 uint32_t index; |
| (...skipping 9809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14972 } | 14970 } |
| 14973 return NULL; | 14971 return NULL; |
| 14974 } | 14972 } |
| 14975 | 14973 |
| 14976 | 14974 |
| 14977 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 14975 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
| 14978 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 14976 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
| 14979 } | 14977 } |
| 14980 | 14978 |
| 14981 } } // namespace v8::internal | 14979 } } // namespace v8::internal |
| OLD | NEW |