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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 Handle<JSObject> boilerplate = | 238 Handle<JSObject> boilerplate = |
239 isolate->factory()->NewJSObjectFromMap(map, pretenure_flag); | 239 isolate->factory()->NewJSObjectFromMap(map, pretenure_flag); |
240 | 240 |
241 // Normalize the elements of the boilerplate to save space if needed. | 241 // Normalize the elements of the boilerplate to save space if needed. |
242 if (!should_have_fast_elements) JSObject::NormalizeElements(boilerplate); | 242 if (!should_have_fast_elements) JSObject::NormalizeElements(boilerplate); |
243 | 243 |
244 // Add the constant properties to the boilerplate. | 244 // Add the constant properties to the boilerplate. |
245 int length = constant_properties->length(); | 245 int length = constant_properties->length(); |
246 bool should_transform = | 246 bool should_transform = |
247 !is_result_from_cache && boilerplate->HasFastProperties(); | 247 !is_result_from_cache && boilerplate->HasFastProperties(); |
248 if (should_transform || has_function_literal) { | 248 bool should_normalize = should_transform || has_function_literal; |
249 // Normalize the properties of object to avoid n^2 behavior | 249 if (should_normalize) { |
250 // when extending the object multiple properties. Indicate the number of | 250 // TODO(verwaest): We might not want to ever normalize here. |
251 // properties to be added. | |
252 JSObject::NormalizeProperties( | 251 JSObject::NormalizeProperties( |
253 boilerplate, KEEP_INOBJECT_PROPERTIES, length / 2); | 252 boilerplate, KEEP_INOBJECT_PROPERTIES, length / 2); |
254 } | 253 } |
| 254 Object::ValueType value_type = should_normalize |
| 255 ? Object::FORCE_TAGGED : Object::OPTIMAL_REPRESENTATION; |
255 | 256 |
256 // TODO(verwaest): Support tracking representations in the boilerplate. | 257 // TODO(verwaest): Support tracking representations in the boilerplate. |
257 for (int index = 0; index < length; index +=2) { | 258 for (int index = 0; index < length; index +=2) { |
258 Handle<Object> key(constant_properties->get(index+0), isolate); | 259 Handle<Object> key(constant_properties->get(index+0), isolate); |
259 Handle<Object> value(constant_properties->get(index+1), isolate); | 260 Handle<Object> value(constant_properties->get(index+1), isolate); |
260 if (value->IsFixedArray()) { | 261 if (value->IsFixedArray()) { |
261 // The value contains the constant_properties of a | 262 // The value contains the constant_properties of a |
262 // simple object or array literal. | 263 // simple object or array literal. |
263 Handle<FixedArray> array = Handle<FixedArray>::cast(value); | 264 Handle<FixedArray> array = Handle<FixedArray>::cast(value); |
264 ASSIGN_RETURN_ON_EXCEPTION( | 265 ASSIGN_RETURN_ON_EXCEPTION( |
265 isolate, value, | 266 isolate, value, |
266 CreateLiteralBoilerplate(isolate, literals, array), | 267 CreateLiteralBoilerplate(isolate, literals, array), |
267 Object); | 268 Object); |
268 } | 269 } |
269 MaybeHandle<Object> maybe_result; | 270 MaybeHandle<Object> maybe_result; |
270 uint32_t element_index = 0; | 271 uint32_t element_index = 0; |
271 StoreMode mode = value->IsJSObject() ? FORCE_FIELD : ALLOW_AS_CONSTANT; | 272 StoreMode mode = value->IsJSObject() ? FORCE_FIELD : ALLOW_AS_CONSTANT; |
272 if (key->IsInternalizedString()) { | 273 if (key->IsInternalizedString()) { |
273 if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) { | 274 if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) { |
274 // Array index as string (uint32). | 275 // Array index as string (uint32). |
275 maybe_result = JSObject::SetOwnElement( | 276 maybe_result = JSObject::SetOwnElement( |
276 boilerplate, element_index, value, SLOPPY); | 277 boilerplate, element_index, value, SLOPPY); |
277 } else { | 278 } else { |
278 Handle<String> name(String::cast(*key)); | 279 Handle<String> name(String::cast(*key)); |
279 ASSERT(!name->AsArrayIndex(&element_index)); | 280 ASSERT(!name->AsArrayIndex(&element_index)); |
280 maybe_result = JSObject::SetOwnPropertyIgnoreAttributes( | 281 maybe_result = JSObject::SetOwnPropertyIgnoreAttributes( |
281 boilerplate, name, value, NONE, | 282 boilerplate, name, value, NONE, |
282 Object::OPTIMAL_REPRESENTATION, mode); | 283 value_type, mode); |
283 } | 284 } |
284 } else if (key->ToArrayIndex(&element_index)) { | 285 } else if (key->ToArrayIndex(&element_index)) { |
285 // Array index (uint32). | 286 // Array index (uint32). |
286 maybe_result = JSObject::SetOwnElement( | 287 maybe_result = JSObject::SetOwnElement( |
287 boilerplate, element_index, value, SLOPPY); | 288 boilerplate, element_index, value, SLOPPY); |
288 } else { | 289 } else { |
289 // Non-uint32 number. | 290 // Non-uint32 number. |
290 ASSERT(key->IsNumber()); | 291 ASSERT(key->IsNumber()); |
291 double num = key->Number(); | 292 double num = key->Number(); |
292 char arr[100]; | 293 char arr[100]; |
293 Vector<char> buffer(arr, ARRAY_SIZE(arr)); | 294 Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
294 const char* str = DoubleToCString(num, buffer); | 295 const char* str = DoubleToCString(num, buffer); |
295 Handle<String> name = isolate->factory()->NewStringFromAsciiChecked(str); | 296 Handle<String> name = isolate->factory()->NewStringFromAsciiChecked(str); |
296 maybe_result = JSObject::SetOwnPropertyIgnoreAttributes( | 297 maybe_result = JSObject::SetOwnPropertyIgnoreAttributes( |
297 boilerplate, name, value, NONE, | 298 boilerplate, name, value, NONE, |
298 Object::OPTIMAL_REPRESENTATION, mode); | 299 value_type, mode); |
299 } | 300 } |
300 // If setting the property on the boilerplate throws an | 301 // If setting the property on the boilerplate throws an |
301 // exception, the exception is converted to an empty handle in | 302 // exception, the exception is converted to an empty handle in |
302 // the handle based operations. In that case, we need to | 303 // the handle based operations. In that case, we need to |
303 // convert back to an exception. | 304 // convert back to an exception. |
304 RETURN_ON_EXCEPTION(isolate, maybe_result, Object); | 305 RETURN_ON_EXCEPTION(isolate, maybe_result, Object); |
305 } | 306 } |
306 | 307 |
307 // Transform to fast properties if necessary. For object literals with | 308 // Transform to fast properties if necessary. For object literals with |
308 // containing function literals we defer this operation until after all | 309 // containing function literals we defer this operation until after all |
(...skipping 14893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15202 } | 15203 } |
15203 return NULL; | 15204 return NULL; |
15204 } | 15205 } |
15205 | 15206 |
15206 | 15207 |
15207 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15208 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
15208 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15209 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
15209 } | 15210 } |
15210 | 15211 |
15211 } } // namespace v8::internal | 15212 } } // namespace v8::internal |
OLD | NEW |