| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 ASSERT(index == number_of_string_keys); | 206 ASSERT(index == number_of_string_keys); |
| 207 } | 207 } |
| 208 *is_result_from_cache = true; | 208 *is_result_from_cache = true; |
| 209 return isolate->factory()->ObjectLiteralMapFromCache(context, keys); | 209 return isolate->factory()->ObjectLiteralMapFromCache(context, keys); |
| 210 } | 210 } |
| 211 *is_result_from_cache = false; | 211 *is_result_from_cache = false; |
| 212 return Map::Create(handle(context->object_function()), number_of_properties); | 212 return Map::Create(handle(context->object_function()), number_of_properties); |
| 213 } | 213 } |
| 214 | 214 |
| 215 | 215 |
| 216 static Handle<Object> CreateLiteralBoilerplate( | 216 MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate( |
| 217 Isolate* isolate, | 217 Isolate* isolate, |
| 218 Handle<FixedArray> literals, | 218 Handle<FixedArray> literals, |
| 219 Handle<FixedArray> constant_properties); | 219 Handle<FixedArray> constant_properties); |
| 220 | 220 |
| 221 | 221 |
| 222 static Handle<Object> CreateObjectLiteralBoilerplate( | 222 MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate( |
| 223 Isolate* isolate, | 223 Isolate* isolate, |
| 224 Handle<FixedArray> literals, | 224 Handle<FixedArray> literals, |
| 225 Handle<FixedArray> constant_properties, | 225 Handle<FixedArray> constant_properties, |
| 226 bool should_have_fast_elements, | 226 bool should_have_fast_elements, |
| 227 bool has_function_literal) { | 227 bool has_function_literal) { |
| 228 // Get the native context from the literals array. This is the | 228 // Get the native context from the literals array. This is the |
| 229 // context in which the function was created and we use the object | 229 // context in which the function was created and we use the object |
| 230 // function from this context to create the object literal. We do | 230 // function from this context to create the object literal. We do |
| 231 // not use the object function from the current native context | 231 // not use the object function from the current native context |
| 232 // because this might be the object function from another context | 232 // because this might be the object function from another context |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 } | 267 } |
| 268 | 268 |
| 269 // TODO(verwaest): Support tracking representations in the boilerplate. | 269 // TODO(verwaest): Support tracking representations in the boilerplate. |
| 270 for (int index = 0; index < length; index +=2) { | 270 for (int index = 0; index < length; index +=2) { |
| 271 Handle<Object> key(constant_properties->get(index+0), isolate); | 271 Handle<Object> key(constant_properties->get(index+0), isolate); |
| 272 Handle<Object> value(constant_properties->get(index+1), isolate); | 272 Handle<Object> value(constant_properties->get(index+1), isolate); |
| 273 if (value->IsFixedArray()) { | 273 if (value->IsFixedArray()) { |
| 274 // The value contains the constant_properties of a | 274 // The value contains the constant_properties of a |
| 275 // simple object or array literal. | 275 // simple object or array literal. |
| 276 Handle<FixedArray> array = Handle<FixedArray>::cast(value); | 276 Handle<FixedArray> array = Handle<FixedArray>::cast(value); |
| 277 value = CreateLiteralBoilerplate(isolate, literals, array); | 277 ASSIGN_RETURN_ON_EXCEPTION( |
| 278 if (value.is_null()) return value; | 278 isolate, value, |
| 279 CreateLiteralBoilerplate(isolate, literals, array), |
| 280 Object); |
| 279 } | 281 } |
| 280 Handle<Object> result; | 282 MaybeHandle<Object> maybe_result; |
| 281 uint32_t element_index = 0; | 283 uint32_t element_index = 0; |
| 282 StoreMode mode = value->IsJSObject() ? FORCE_FIELD : ALLOW_AS_CONSTANT; | 284 StoreMode mode = value->IsJSObject() ? FORCE_FIELD : ALLOW_AS_CONSTANT; |
| 283 if (key->IsInternalizedString()) { | 285 if (key->IsInternalizedString()) { |
| 284 if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) { | 286 if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) { |
| 285 // Array index as string (uint32). | 287 // Array index as string (uint32). |
| 286 result = JSObject::SetOwnElement( | 288 maybe_result = JSObject::SetOwnElement( |
| 287 boilerplate, element_index, value, SLOPPY); | 289 boilerplate, element_index, value, SLOPPY); |
| 288 } else { | 290 } else { |
| 289 Handle<String> name(String::cast(*key)); | 291 Handle<String> name(String::cast(*key)); |
| 290 ASSERT(!name->AsArrayIndex(&element_index)); | 292 ASSERT(!name->AsArrayIndex(&element_index)); |
| 291 result = JSObject::SetLocalPropertyIgnoreAttributes( | 293 maybe_result = JSObject::SetLocalPropertyIgnoreAttributes( |
| 292 boilerplate, name, value, NONE, | 294 boilerplate, name, value, NONE, |
| 293 Object::OPTIMAL_REPRESENTATION, mode); | 295 Object::OPTIMAL_REPRESENTATION, mode); |
| 294 } | 296 } |
| 295 } else if (key->ToArrayIndex(&element_index)) { | 297 } else if (key->ToArrayIndex(&element_index)) { |
| 296 // Array index (uint32). | 298 // Array index (uint32). |
| 297 result = JSObject::SetOwnElement( | 299 maybe_result = JSObject::SetOwnElement( |
| 298 boilerplate, element_index, value, SLOPPY); | 300 boilerplate, element_index, value, SLOPPY); |
| 299 } else { | 301 } else { |
| 300 // Non-uint32 number. | 302 // Non-uint32 number. |
| 301 ASSERT(key->IsNumber()); | 303 ASSERT(key->IsNumber()); |
| 302 double num = key->Number(); | 304 double num = key->Number(); |
| 303 char arr[100]; | 305 char arr[100]; |
| 304 Vector<char> buffer(arr, ARRAY_SIZE(arr)); | 306 Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
| 305 const char* str = DoubleToCString(num, buffer); | 307 const char* str = DoubleToCString(num, buffer); |
| 306 Handle<String> name = | 308 Handle<String> name = |
| 307 isolate->factory()->NewStringFromAscii(CStrVector(str)); | 309 isolate->factory()->NewStringFromAscii(CStrVector(str)); |
| 308 result = JSObject::SetLocalPropertyIgnoreAttributes( | 310 maybe_result = JSObject::SetLocalPropertyIgnoreAttributes( |
| 309 boilerplate, name, value, NONE, | 311 boilerplate, name, value, NONE, |
| 310 Object::OPTIMAL_REPRESENTATION, mode); | 312 Object::OPTIMAL_REPRESENTATION, mode); |
| 311 } | 313 } |
| 312 // If setting the property on the boilerplate throws an | 314 // If setting the property on the boilerplate throws an |
| 313 // exception, the exception is converted to an empty handle in | 315 // exception, the exception is converted to an empty handle in |
| 314 // the handle based operations. In that case, we need to | 316 // the handle based operations. In that case, we need to |
| 315 // convert back to an exception. | 317 // convert back to an exception. |
| 316 if (result.is_null()) return result; | 318 RETURN_ON_EXCEPTION(isolate, maybe_result, Object); |
| 317 } | 319 } |
| 318 | 320 |
| 319 // Transform to fast properties if necessary. For object literals with | 321 // Transform to fast properties if necessary. For object literals with |
| 320 // containing function literals we defer this operation until after all | 322 // containing function literals we defer this operation until after all |
| 321 // computed properties have been assigned so that we can generate | 323 // computed properties have been assigned so that we can generate |
| 322 // constant function properties. | 324 // constant function properties. |
| 323 if (should_transform && !has_function_literal) { | 325 if (should_transform && !has_function_literal) { |
| 324 JSObject::TransformToFastProperties( | 326 JSObject::TransformToFastProperties( |
| 325 boilerplate, boilerplate->map()->unused_property_fields()); | 327 boilerplate, boilerplate->map()->unused_property_fields()); |
| 326 } | 328 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 340 JSObject::TransitionElementsKind(Handle<JSObject>::cast(object), to_kind); | 342 JSObject::TransitionElementsKind(Handle<JSObject>::cast(object), to_kind); |
| 341 return *object; | 343 return *object; |
| 342 } | 344 } |
| 343 return isolate->ThrowIllegalOperation(); | 345 return isolate->ThrowIllegalOperation(); |
| 344 } | 346 } |
| 345 | 347 |
| 346 | 348 |
| 347 static const int kSmiLiteralMinimumLength = 1024; | 349 static const int kSmiLiteralMinimumLength = 1024; |
| 348 | 350 |
| 349 | 351 |
| 350 Handle<Object> Runtime::CreateArrayLiteralBoilerplate( | 352 MaybeHandle<Object> Runtime::CreateArrayLiteralBoilerplate( |
| 351 Isolate* isolate, | 353 Isolate* isolate, |
| 352 Handle<FixedArray> literals, | 354 Handle<FixedArray> literals, |
| 353 Handle<FixedArray> elements) { | 355 Handle<FixedArray> elements) { |
| 354 // Create the JSArray. | 356 // Create the JSArray. |
| 355 Handle<JSFunction> constructor( | 357 Handle<JSFunction> constructor( |
| 356 JSFunction::NativeContextFromLiterals(*literals)->array_function()); | 358 JSFunction::NativeContextFromLiterals(*literals)->array_function()); |
| 357 | 359 |
| 358 PretenureFlag pretenure_flag = | 360 PretenureFlag pretenure_flag = |
| 359 isolate->heap()->InNewSpace(*literals) ? NOT_TENURED : TENURED; | 361 isolate->heap()->InNewSpace(*literals) ? NOT_TENURED : TENURED; |
| 360 | 362 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 Handle<FixedArray>::cast(constant_elements_values); | 401 Handle<FixedArray>::cast(constant_elements_values); |
| 400 Handle<FixedArray> fixed_array_values_copy = | 402 Handle<FixedArray> fixed_array_values_copy = |
| 401 isolate->factory()->CopyFixedArray(fixed_array_values); | 403 isolate->factory()->CopyFixedArray(fixed_array_values); |
| 402 copied_elements_values = fixed_array_values_copy; | 404 copied_elements_values = fixed_array_values_copy; |
| 403 for (int i = 0; i < fixed_array_values->length(); i++) { | 405 for (int i = 0; i < fixed_array_values->length(); i++) { |
| 404 Object* current = fixed_array_values->get(i); | 406 Object* current = fixed_array_values->get(i); |
| 405 if (current->IsFixedArray()) { | 407 if (current->IsFixedArray()) { |
| 406 // The value contains the constant_properties of a | 408 // The value contains the constant_properties of a |
| 407 // simple object or array literal. | 409 // simple object or array literal. |
| 408 Handle<FixedArray> fa(FixedArray::cast(fixed_array_values->get(i))); | 410 Handle<FixedArray> fa(FixedArray::cast(fixed_array_values->get(i))); |
| 409 Handle<Object> result = | 411 Handle<Object> result; |
| 410 CreateLiteralBoilerplate(isolate, literals, fa); | 412 ASSIGN_RETURN_ON_EXCEPTION( |
| 411 if (result.is_null()) return result; | 413 isolate, result, |
| 414 CreateLiteralBoilerplate(isolate, literals, fa), |
| 415 Object); |
| 412 fixed_array_values_copy->set(i, *result); | 416 fixed_array_values_copy->set(i, *result); |
| 413 } | 417 } |
| 414 } | 418 } |
| 415 } | 419 } |
| 416 } | 420 } |
| 417 object->set_elements(*copied_elements_values); | 421 object->set_elements(*copied_elements_values); |
| 418 object->set_length(Smi::FromInt(copied_elements_values->length())); | 422 object->set_length(Smi::FromInt(copied_elements_values->length())); |
| 419 | 423 |
| 420 // Ensure that the boilerplate object has FAST_*_ELEMENTS, unless the flag is | 424 // Ensure that the boilerplate object has FAST_*_ELEMENTS, unless the flag is |
| 421 // on or the object is larger than the threshold. | 425 // on or the object is larger than the threshold. |
| 422 if (!FLAG_smi_only_arrays && | 426 if (!FLAG_smi_only_arrays && |
| 423 constant_elements_values->length() < kSmiLiteralMinimumLength) { | 427 constant_elements_values->length() < kSmiLiteralMinimumLength) { |
| 424 ElementsKind elements_kind = object->GetElementsKind(); | 428 ElementsKind elements_kind = object->GetElementsKind(); |
| 425 if (!IsFastObjectElementsKind(elements_kind)) { | 429 if (!IsFastObjectElementsKind(elements_kind)) { |
| 426 if (IsFastHoleyElementsKind(elements_kind)) { | 430 if (IsFastHoleyElementsKind(elements_kind)) { |
| 427 CHECK(!TransitionElements(object, FAST_HOLEY_ELEMENTS, | 431 CHECK(!TransitionElements(object, FAST_HOLEY_ELEMENTS, |
| 428 isolate)->IsFailure()); | 432 isolate)->IsFailure()); |
| 429 } else { | 433 } else { |
| 430 CHECK(!TransitionElements(object, FAST_ELEMENTS, isolate)->IsFailure()); | 434 CHECK(!TransitionElements(object, FAST_ELEMENTS, isolate)->IsFailure()); |
| 431 } | 435 } |
| 432 } | 436 } |
| 433 } | 437 } |
| 434 | 438 |
| 435 object->ValidateElements(); | 439 object->ValidateElements(); |
| 436 return object; | 440 return object; |
| 437 } | 441 } |
| 438 | 442 |
| 439 | 443 |
| 440 static Handle<Object> CreateLiteralBoilerplate( | 444 MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate( |
| 441 Isolate* isolate, | 445 Isolate* isolate, |
| 442 Handle<FixedArray> literals, | 446 Handle<FixedArray> literals, |
| 443 Handle<FixedArray> array) { | 447 Handle<FixedArray> array) { |
| 444 Handle<FixedArray> elements = CompileTimeValue::GetElements(array); | 448 Handle<FixedArray> elements = CompileTimeValue::GetElements(array); |
| 445 const bool kHasNoFunctionLiteral = false; | 449 const bool kHasNoFunctionLiteral = false; |
| 446 switch (CompileTimeValue::GetLiteralType(array)) { | 450 switch (CompileTimeValue::GetLiteralType(array)) { |
| 447 case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS: | 451 case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS: |
| 448 return CreateObjectLiteralBoilerplate(isolate, | 452 return CreateObjectLiteralBoilerplate(isolate, |
| 449 literals, | 453 literals, |
| 450 elements, | 454 elements, |
| 451 true, | 455 true, |
| 452 kHasNoFunctionLiteral); | 456 kHasNoFunctionLiteral); |
| 453 case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS: | 457 case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS: |
| 454 return CreateObjectLiteralBoilerplate(isolate, | 458 return CreateObjectLiteralBoilerplate(isolate, |
| 455 literals, | 459 literals, |
| 456 elements, | 460 elements, |
| 457 false, | 461 false, |
| 458 kHasNoFunctionLiteral); | 462 kHasNoFunctionLiteral); |
| 459 case CompileTimeValue::ARRAY_LITERAL: | 463 case CompileTimeValue::ARRAY_LITERAL: |
| 460 return Runtime::CreateArrayLiteralBoilerplate( | 464 return Runtime::CreateArrayLiteralBoilerplate( |
| 461 isolate, literals, elements); | 465 isolate, literals, elements); |
| 462 default: | 466 default: |
| 463 UNREACHABLE(); | 467 UNREACHABLE(); |
| 464 return Handle<Object>::null(); | 468 return MaybeHandle<Object>(); |
| 465 } | 469 } |
| 466 } | 470 } |
| 467 | 471 |
| 468 | 472 |
| 469 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_CreateObjectLiteral) { | 473 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_CreateObjectLiteral) { |
| 470 HandleScope scope(isolate); | 474 HandleScope scope(isolate); |
| 471 ASSERT(args.length() == 4); | 475 ASSERT(args.length() == 4); |
| 472 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 476 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 473 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 477 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 474 CONVERT_ARG_HANDLE_CHECKED(FixedArray, constant_properties, 2); | 478 CONVERT_ARG_HANDLE_CHECKED(FixedArray, constant_properties, 2); |
| 475 CONVERT_SMI_ARG_CHECKED(flags, 3); | 479 CONVERT_SMI_ARG_CHECKED(flags, 3); |
| 476 bool should_have_fast_elements = (flags & ObjectLiteral::kFastElements) != 0; | 480 bool should_have_fast_elements = (flags & ObjectLiteral::kFastElements) != 0; |
| 477 bool has_function_literal = (flags & ObjectLiteral::kHasFunction) != 0; | 481 bool has_function_literal = (flags & ObjectLiteral::kHasFunction) != 0; |
| 478 | 482 |
| 479 // Check if boilerplate exists. If not, create it first. | 483 // Check if boilerplate exists. If not, create it first. |
| 480 Handle<Object> literal_site(literals->get(literals_index), isolate); | 484 Handle<Object> literal_site(literals->get(literals_index), isolate); |
| 481 Handle<AllocationSite> site; | 485 Handle<AllocationSite> site; |
| 482 Handle<JSObject> boilerplate; | 486 Handle<JSObject> boilerplate; |
| 483 if (*literal_site == isolate->heap()->undefined_value()) { | 487 if (*literal_site == isolate->heap()->undefined_value()) { |
| 484 Handle<Object> raw_boilerplate = CreateObjectLiteralBoilerplate( | 488 Handle<Object> raw_boilerplate; |
| 485 isolate, | 489 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 486 literals, | 490 isolate, raw_boilerplate, |
| 487 constant_properties, | 491 CreateObjectLiteralBoilerplate( |
| 488 should_have_fast_elements, | 492 isolate, |
| 489 has_function_literal); | 493 literals, |
| 490 RETURN_IF_EMPTY_HANDLE(isolate, raw_boilerplate); | 494 constant_properties, |
| 495 should_have_fast_elements, |
| 496 has_function_literal)); |
| 491 boilerplate = Handle<JSObject>::cast(raw_boilerplate); | 497 boilerplate = Handle<JSObject>::cast(raw_boilerplate); |
| 492 | 498 |
| 493 AllocationSiteCreationContext creation_context(isolate); | 499 AllocationSiteCreationContext creation_context(isolate); |
| 494 site = creation_context.EnterNewScope(); | 500 site = creation_context.EnterNewScope(); |
| 495 RETURN_IF_EMPTY_HANDLE(isolate, | 501 RETURN_IF_EMPTY_HANDLE(isolate, |
| 496 JSObject::DeepWalk(boilerplate, &creation_context)); | 502 JSObject::DeepWalk(boilerplate, &creation_context)); |
| 497 creation_context.ExitScope(site, boilerplate); | 503 creation_context.ExitScope(site, boilerplate); |
| 498 | 504 |
| 499 // Update the functions literal and return the boilerplate. | 505 // Update the functions literal and return the boilerplate. |
| 500 literals->set(literals_index, *site); | 506 literals->set(literals_index, *site); |
| 501 } else { | 507 } else { |
| 502 site = Handle<AllocationSite>::cast(literal_site); | 508 site = Handle<AllocationSite>::cast(literal_site); |
| 503 boilerplate = Handle<JSObject>(JSObject::cast(site->transition_info()), | 509 boilerplate = Handle<JSObject>(JSObject::cast(site->transition_info()), |
| 504 isolate); | 510 isolate); |
| 505 } | 511 } |
| 506 | 512 |
| 507 AllocationSiteUsageContext usage_context(isolate, site, true); | 513 AllocationSiteUsageContext usage_context(isolate, site, true); |
| 508 usage_context.EnterNewScope(); | 514 usage_context.EnterNewScope(); |
| 509 Handle<Object> copy = JSObject::DeepCopy(boilerplate, &usage_context); | 515 Handle<Object> copy = JSObject::DeepCopy(boilerplate, &usage_context); |
| 510 usage_context.ExitScope(site, boilerplate); | 516 usage_context.ExitScope(site, boilerplate); |
| 511 RETURN_IF_EMPTY_HANDLE(isolate, copy); | 517 RETURN_IF_EMPTY_HANDLE(isolate, copy); |
| 512 return *copy; | 518 return *copy; |
| 513 } | 519 } |
| 514 | 520 |
| 515 | 521 |
| 516 static Handle<AllocationSite> GetLiteralAllocationSite( | 522 MUST_USE_RESULT static MaybeHandle<AllocationSite> GetLiteralAllocationSite( |
| 517 Isolate* isolate, | 523 Isolate* isolate, |
| 518 Handle<FixedArray> literals, | 524 Handle<FixedArray> literals, |
| 519 int literals_index, | 525 int literals_index, |
| 520 Handle<FixedArray> elements) { | 526 Handle<FixedArray> elements) { |
| 521 // Check if boilerplate exists. If not, create it first. | 527 // Check if boilerplate exists. If not, create it first. |
| 522 Handle<Object> literal_site(literals->get(literals_index), isolate); | 528 Handle<Object> literal_site(literals->get(literals_index), isolate); |
| 523 Handle<AllocationSite> site; | 529 Handle<AllocationSite> site; |
| 524 if (*literal_site == isolate->heap()->undefined_value()) { | 530 if (*literal_site == isolate->heap()->undefined_value()) { |
| 525 ASSERT(*elements != isolate->heap()->empty_fixed_array()); | 531 ASSERT(*elements != isolate->heap()->empty_fixed_array()); |
| 526 Handle<Object> boilerplate = | 532 Handle<Object> boilerplate; |
| 527 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); | 533 ASSIGN_RETURN_ON_EXCEPTION( |
| 528 if (boilerplate.is_null()) return Handle<AllocationSite>::null(); | 534 isolate, boilerplate, |
| 535 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements), |
| 536 AllocationSite); |
| 529 | 537 |
| 530 AllocationSiteCreationContext creation_context(isolate); | 538 AllocationSiteCreationContext creation_context(isolate); |
| 531 site = creation_context.EnterNewScope(); | 539 site = creation_context.EnterNewScope(); |
| 532 if (JSObject::DeepWalk(Handle<JSObject>::cast(boilerplate), | 540 if (JSObject::DeepWalk(Handle<JSObject>::cast(boilerplate), |
| 533 &creation_context).is_null()) { | 541 &creation_context).is_null()) { |
| 534 return Handle<AllocationSite>::null(); | 542 return Handle<AllocationSite>::null(); |
| 535 } | 543 } |
| 536 creation_context.ExitScope(site, Handle<JSObject>::cast(boilerplate)); | 544 creation_context.ExitScope(site, Handle<JSObject>::cast(boilerplate)); |
| 537 | 545 |
| 538 literals->set(literals_index, *site); | 546 literals->set(literals_index, *site); |
| 539 } else { | 547 } else { |
| 540 site = Handle<AllocationSite>::cast(literal_site); | 548 site = Handle<AllocationSite>::cast(literal_site); |
| 541 } | 549 } |
| 542 | 550 |
| 543 return site; | 551 return site; |
| 544 } | 552 } |
| 545 | 553 |
| 546 | 554 |
| 547 static MaybeObject* CreateArrayLiteralImpl(Isolate* isolate, | 555 static MaybeObject* CreateArrayLiteralImpl(Isolate* isolate, |
| 548 Handle<FixedArray> literals, | 556 Handle<FixedArray> literals, |
| 549 int literals_index, | 557 int literals_index, |
| 550 Handle<FixedArray> elements, | 558 Handle<FixedArray> elements, |
| 551 int flags) { | 559 int flags) { |
| 552 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, | 560 Handle<AllocationSite> site; |
| 553 literals_index, elements); | 561 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 554 RETURN_IF_EMPTY_HANDLE(isolate, site); | 562 isolate, site, |
| 563 GetLiteralAllocationSite(isolate, literals, literals_index, elements)); |
| 555 | 564 |
| 556 bool enable_mementos = (flags & ArrayLiteral::kDisableMementos) == 0; | 565 bool enable_mementos = (flags & ArrayLiteral::kDisableMementos) == 0; |
| 557 Handle<JSObject> boilerplate(JSObject::cast(site->transition_info())); | 566 Handle<JSObject> boilerplate(JSObject::cast(site->transition_info())); |
| 558 AllocationSiteUsageContext usage_context(isolate, site, enable_mementos); | 567 AllocationSiteUsageContext usage_context(isolate, site, enable_mementos); |
| 559 usage_context.EnterNewScope(); | 568 usage_context.EnterNewScope(); |
| 560 JSObject::DeepCopyHints hints = (flags & ArrayLiteral::kShallowElements) == 0 | 569 JSObject::DeepCopyHints hints = (flags & ArrayLiteral::kShallowElements) == 0 |
| 561 ? JSObject::kNoHints | 570 ? JSObject::kNoHints |
| 562 : JSObject::kObjectIsShallowArray; | 571 : JSObject::kObjectIsShallowArray; |
| 563 Handle<JSObject> copy = JSObject::DeepCopy(boilerplate, &usage_context, | 572 Handle<JSObject> copy = JSObject::DeepCopy(boilerplate, &usage_context, |
| 564 hints); | 573 hints); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 634 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
| 626 Handle<JSObject> registry = isolate->GetSymbolRegistry(); | 635 Handle<JSObject> registry = isolate->GetSymbolRegistry(); |
| 627 Handle<String> part = isolate->factory()->private_intern_string(); | 636 Handle<String> part = isolate->factory()->private_intern_string(); |
| 628 Handle<JSObject> privates = | 637 Handle<JSObject> privates = |
| 629 Handle<JSObject>::cast(Object::GetPropertyOrElement(registry, part)); | 638 Handle<JSObject>::cast(Object::GetPropertyOrElement(registry, part)); |
| 630 Handle<Object> symbol = Object::GetPropertyOrElement(privates, name); | 639 Handle<Object> symbol = Object::GetPropertyOrElement(privates, name); |
| 631 if (!symbol->IsSymbol()) { | 640 if (!symbol->IsSymbol()) { |
| 632 ASSERT(symbol->IsUndefined()); | 641 ASSERT(symbol->IsUndefined()); |
| 633 symbol = isolate->factory()->NewPrivateSymbol(); | 642 symbol = isolate->factory()->NewPrivateSymbol(); |
| 634 Handle<Symbol>::cast(symbol)->set_name(*name); | 643 Handle<Symbol>::cast(symbol)->set_name(*name); |
| 635 JSObject::SetProperty(privates, name, symbol, NONE, STRICT); | 644 JSObject::SetProperty(privates, name, symbol, NONE, STRICT).Assert(); |
| 636 } | 645 } |
| 637 return *symbol; | 646 return *symbol; |
| 638 } | 647 } |
| 639 | 648 |
| 640 | 649 |
| 641 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewSymbolWrapper) { | 650 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewSymbolWrapper) { |
| 642 ASSERT(args.length() == 1); | 651 ASSERT(args.length() == 1); |
| 643 CONVERT_ARG_CHECKED(Symbol, symbol, 0); | 652 CONVERT_ARG_CHECKED(Symbol, symbol, 0); |
| 644 return symbol->ToObject(isolate); | 653 return symbol->ToObject(isolate); |
| 645 } | 654 } |
| (...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2200 } | 2209 } |
| 2201 // If the existing property is not configurable, keep its attributes. | 2210 // If the existing property is not configurable, keep its attributes. |
| 2202 attr = lookup.GetAttributes(); | 2211 attr = lookup.GetAttributes(); |
| 2203 } | 2212 } |
| 2204 // Define or redefine own property. | 2213 // Define or redefine own property. |
| 2205 RETURN_IF_EMPTY_HANDLE(isolate, | 2214 RETURN_IF_EMPTY_HANDLE(isolate, |
| 2206 JSObject::SetLocalPropertyIgnoreAttributes( | 2215 JSObject::SetLocalPropertyIgnoreAttributes( |
| 2207 global, name, value, static_cast<PropertyAttributes>(attr))); | 2216 global, name, value, static_cast<PropertyAttributes>(attr))); |
| 2208 } else { | 2217 } else { |
| 2209 // Do a [[Put]] on the existing (own) property. | 2218 // Do a [[Put]] on the existing (own) property. |
| 2210 RETURN_IF_EMPTY_HANDLE(isolate, | 2219 RETURN_FAILURE_ON_EXCEPTION( |
| 2220 isolate, |
| 2211 JSObject::SetProperty( | 2221 JSObject::SetProperty( |
| 2212 global, name, value, static_cast<PropertyAttributes>(attr), | 2222 global, name, value, static_cast<PropertyAttributes>(attr), |
| 2213 strict_mode)); | 2223 strict_mode)); |
| 2214 } | 2224 } |
| 2215 } | 2225 } |
| 2216 | 2226 |
| 2217 ASSERT(!isolate->has_pending_exception()); | 2227 ASSERT(!isolate->has_pending_exception()); |
| 2218 return isolate->heap()->undefined_value(); | 2228 return isolate->heap()->undefined_value(); |
| 2219 } | 2229 } |
| 2220 | 2230 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2256 if (index >= 0) { | 2266 if (index >= 0) { |
| 2257 ASSERT(holder.is_identical_to(context)); | 2267 ASSERT(holder.is_identical_to(context)); |
| 2258 if (((attributes & READ_ONLY) == 0) || | 2268 if (((attributes & READ_ONLY) == 0) || |
| 2259 context->get(index)->IsTheHole()) { | 2269 context->get(index)->IsTheHole()) { |
| 2260 context->set(index, *initial_value); | 2270 context->set(index, *initial_value); |
| 2261 } | 2271 } |
| 2262 } else { | 2272 } else { |
| 2263 // Slow case: The property is in the context extension object of a | 2273 // Slow case: The property is in the context extension object of a |
| 2264 // function context or the global object of a native context. | 2274 // function context or the global object of a native context. |
| 2265 Handle<JSObject> object = Handle<JSObject>::cast(holder); | 2275 Handle<JSObject> object = Handle<JSObject>::cast(holder); |
| 2266 RETURN_IF_EMPTY_HANDLE( | 2276 RETURN_FAILURE_ON_EXCEPTION( |
| 2267 isolate, | 2277 isolate, |
| 2268 JSReceiver::SetProperty(object, name, initial_value, mode, SLOPPY)); | 2278 JSReceiver::SetProperty(object, name, initial_value, mode, SLOPPY)); |
| 2269 } | 2279 } |
| 2270 } | 2280 } |
| 2271 | 2281 |
| 2272 } else { | 2282 } else { |
| 2273 // The property is not in the function context. It needs to be | 2283 // The property is not in the function context. It needs to be |
| 2274 // "declared" in the function context's extension context or as a | 2284 // "declared" in the function context's extension context or as a |
| 2275 // property of the the global object. | 2285 // property of the the global object. |
| 2276 Handle<JSObject> object; | 2286 Handle<JSObject> object; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2303 object->Lookup(*name, &lookup); | 2313 object->Lookup(*name, &lookup); |
| 2304 if (lookup.IsPropertyCallbacks()) { | 2314 if (lookup.IsPropertyCallbacks()) { |
| 2305 return ThrowRedeclarationError(isolate, name); | 2315 return ThrowRedeclarationError(isolate, name); |
| 2306 } | 2316 } |
| 2307 } | 2317 } |
| 2308 if (object->IsJSGlobalObject()) { | 2318 if (object->IsJSGlobalObject()) { |
| 2309 // Define own property on the global object. | 2319 // Define own property on the global object. |
| 2310 RETURN_IF_EMPTY_HANDLE(isolate, | 2320 RETURN_IF_EMPTY_HANDLE(isolate, |
| 2311 JSObject::SetLocalPropertyIgnoreAttributes(object, name, value, mode)); | 2321 JSObject::SetLocalPropertyIgnoreAttributes(object, name, value, mode)); |
| 2312 } else { | 2322 } else { |
| 2313 RETURN_IF_EMPTY_HANDLE(isolate, | 2323 RETURN_FAILURE_ON_EXCEPTION(isolate, |
| 2314 JSReceiver::SetProperty(object, name, value, mode, SLOPPY)); | 2324 JSReceiver::SetProperty(object, name, value, mode, SLOPPY)); |
| 2315 } | 2325 } |
| 2316 } | 2326 } |
| 2317 | 2327 |
| 2318 return isolate->heap()->undefined_value(); | 2328 return isolate->heap()->undefined_value(); |
| 2319 } | 2329 } |
| 2320 | 2330 |
| 2321 | 2331 |
| 2322 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeVarGlobal) { | 2332 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeVarGlobal) { |
| 2323 HandleScope scope(isolate); | 2333 HandleScope scope(isolate); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2348 LookupResult lookup(isolate); | 2358 LookupResult lookup(isolate); |
| 2349 isolate->context()->global_object()->LocalLookup(*name, &lookup, true); | 2359 isolate->context()->global_object()->LocalLookup(*name, &lookup, true); |
| 2350 if (lookup.IsInterceptor()) { | 2360 if (lookup.IsInterceptor()) { |
| 2351 Handle<JSObject> holder(lookup.holder()); | 2361 Handle<JSObject> holder(lookup.holder()); |
| 2352 PropertyAttributes intercepted = | 2362 PropertyAttributes intercepted = |
| 2353 JSReceiver::GetPropertyAttribute(holder, name); | 2363 JSReceiver::GetPropertyAttribute(holder, name); |
| 2354 if (intercepted != ABSENT && (intercepted & READ_ONLY) == 0) { | 2364 if (intercepted != ABSENT && (intercepted & READ_ONLY) == 0) { |
| 2355 // Found an interceptor that's not read only. | 2365 // Found an interceptor that's not read only. |
| 2356 if (assign) { | 2366 if (assign) { |
| 2357 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 2367 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 2358 Handle<Object> result = JSObject::SetPropertyForResult( | 2368 Handle<Object> result; |
| 2359 holder, &lookup, name, value, attributes, strict_mode); | 2369 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2360 RETURN_IF_EMPTY_HANDLE(isolate, result); | 2370 isolate, result, |
| 2371 JSObject::SetPropertyForResult( |
| 2372 holder, &lookup, name, value, attributes, strict_mode)); |
| 2361 return *result; | 2373 return *result; |
| 2362 } else { | 2374 } else { |
| 2363 return isolate->heap()->undefined_value(); | 2375 return isolate->heap()->undefined_value(); |
| 2364 } | 2376 } |
| 2365 } | 2377 } |
| 2366 } | 2378 } |
| 2367 | 2379 |
| 2368 if (assign) { | 2380 if (assign) { |
| 2369 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 2381 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 2370 Handle<GlobalObject> global(isolate->context()->global_object()); | 2382 Handle<GlobalObject> global(isolate->context()->global_object()); |
| 2371 Handle<Object> result = JSReceiver::SetProperty( | 2383 Handle<Object> result; |
| 2372 global, name, value, attributes, strict_mode); | 2384 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2373 RETURN_IF_EMPTY_HANDLE(isolate, result); | 2385 isolate, result, |
| 2386 JSReceiver::SetProperty(global, name, value, attributes, strict_mode)); |
| 2374 return *result; | 2387 return *result; |
| 2375 } | 2388 } |
| 2376 return isolate->heap()->undefined_value(); | 2389 return isolate->heap()->undefined_value(); |
| 2377 } | 2390 } |
| 2378 | 2391 |
| 2379 | 2392 |
| 2380 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_InitializeConstGlobal) { | 2393 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_InitializeConstGlobal) { |
| 2381 SealHandleScope shs(isolate); | 2394 SealHandleScope shs(isolate); |
| 2382 // All constants are declared with an initial value. The name | 2395 // All constants are declared with an initial value. The name |
| 2383 // of the constant is the first argument and the initial value | 2396 // of the constant is the first argument and the initial value |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2414 if (!lookup.IsReadOnly()) { | 2427 if (!lookup.IsReadOnly()) { |
| 2415 // Restore global object from context (in case of GC) and continue | 2428 // Restore global object from context (in case of GC) and continue |
| 2416 // with setting the value. | 2429 // with setting the value. |
| 2417 HandleScope handle_scope(isolate); | 2430 HandleScope handle_scope(isolate); |
| 2418 Handle<GlobalObject> global(isolate->context()->global_object()); | 2431 Handle<GlobalObject> global(isolate->context()->global_object()); |
| 2419 | 2432 |
| 2420 // BUG 1213575: Handle the case where we have to set a read-only | 2433 // BUG 1213575: Handle the case where we have to set a read-only |
| 2421 // property through an interceptor and only do it if it's | 2434 // property through an interceptor and only do it if it's |
| 2422 // uninitialized, e.g. the hole. Nirk... | 2435 // uninitialized, e.g. the hole. Nirk... |
| 2423 // Passing sloppy mode because the property is writable. | 2436 // Passing sloppy mode because the property is writable. |
| 2424 RETURN_IF_EMPTY_HANDLE( | 2437 RETURN_FAILURE_ON_EXCEPTION( |
| 2425 isolate, | 2438 isolate, |
| 2426 JSReceiver::SetProperty(global, name, value, attributes, SLOPPY)); | 2439 JSReceiver::SetProperty(global, name, value, attributes, SLOPPY)); |
| 2427 return *value; | 2440 return *value; |
| 2428 } | 2441 } |
| 2429 | 2442 |
| 2430 // Set the value, but only if we're assigning the initial value to a | 2443 // Set the value, but only if we're assigning the initial value to a |
| 2431 // constant. For now, we determine this by checking if the | 2444 // constant. For now, we determine this by checking if the |
| 2432 // current value is the hole. | 2445 // current value is the hole. |
| 2433 // Strict mode handling not needed (const is disallowed in strict mode). | 2446 // Strict mode handling not needed (const is disallowed in strict mode). |
| 2434 if (lookup.IsField()) { | 2447 if (lookup.IsField()) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2484 } | 2497 } |
| 2485 return *value; | 2498 return *value; |
| 2486 } | 2499 } |
| 2487 | 2500 |
| 2488 // The property could not be found, we introduce it as a property of the | 2501 // The property could not be found, we introduce it as a property of the |
| 2489 // global object. | 2502 // global object. |
| 2490 if (attributes == ABSENT) { | 2503 if (attributes == ABSENT) { |
| 2491 Handle<JSObject> global = Handle<JSObject>( | 2504 Handle<JSObject> global = Handle<JSObject>( |
| 2492 isolate->context()->global_object()); | 2505 isolate->context()->global_object()); |
| 2493 // Strict mode not needed (const disallowed in strict mode). | 2506 // Strict mode not needed (const disallowed in strict mode). |
| 2494 RETURN_IF_EMPTY_HANDLE( | 2507 RETURN_FAILURE_ON_EXCEPTION( |
| 2495 isolate, | 2508 isolate, |
| 2496 JSReceiver::SetProperty(global, name, value, NONE, SLOPPY)); | 2509 JSReceiver::SetProperty(global, name, value, NONE, SLOPPY)); |
| 2497 return *value; | 2510 return *value; |
| 2498 } | 2511 } |
| 2499 | 2512 |
| 2500 // The property was present in some function's context extension object, | 2513 // The property was present in some function's context extension object, |
| 2501 // as a property on the subject of a with, or as a property of the global | 2514 // as a property on the subject of a with, or as a property of the global |
| 2502 // object. | 2515 // object. |
| 2503 // | 2516 // |
| 2504 // In most situations, eval-introduced consts should still be present in | 2517 // In most situations, eval-introduced consts should still be present in |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2535 } else { | 2548 } else { |
| 2536 // We should not reach here. Any real, named property should be | 2549 // We should not reach here. Any real, named property should be |
| 2537 // either a field or a dictionary slot. | 2550 // either a field or a dictionary slot. |
| 2538 UNREACHABLE(); | 2551 UNREACHABLE(); |
| 2539 } | 2552 } |
| 2540 } else { | 2553 } else { |
| 2541 // The property was found on some other object. Set it if it is not a | 2554 // The property was found on some other object. Set it if it is not a |
| 2542 // read-only property. | 2555 // read-only property. |
| 2543 if ((attributes & READ_ONLY) == 0) { | 2556 if ((attributes & READ_ONLY) == 0) { |
| 2544 // Strict mode not needed (const disallowed in strict mode). | 2557 // Strict mode not needed (const disallowed in strict mode). |
| 2545 RETURN_IF_EMPTY_HANDLE( | 2558 RETURN_FAILURE_ON_EXCEPTION( |
| 2546 isolate, | 2559 isolate, |
| 2547 JSReceiver::SetProperty(object, name, value, attributes, SLOPPY)); | 2560 JSReceiver::SetProperty(object, name, value, attributes, SLOPPY)); |
| 2548 } | 2561 } |
| 2549 } | 2562 } |
| 2550 | 2563 |
| 2551 return *value; | 2564 return *value; |
| 2552 } | 2565 } |
| 2553 | 2566 |
| 2554 | 2567 |
| 2555 RUNTIME_FUNCTION(MaybeObject*, | 2568 RUNTIME_FUNCTION(MaybeObject*, |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2697 Builtins::Name builtin_name) { | 2710 Builtins::Name builtin_name) { |
| 2698 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); | 2711 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); |
| 2699 Handle<Code> code(isolate->builtins()->builtin(builtin_name)); | 2712 Handle<Code> code(isolate->builtins()->builtin(builtin_name)); |
| 2700 Handle<JSFunction> optimized = | 2713 Handle<JSFunction> optimized = |
| 2701 isolate->factory()->NewFunction(key, | 2714 isolate->factory()->NewFunction(key, |
| 2702 JS_OBJECT_TYPE, | 2715 JS_OBJECT_TYPE, |
| 2703 JSObject::kHeaderSize, | 2716 JSObject::kHeaderSize, |
| 2704 code, | 2717 code, |
| 2705 false); | 2718 false); |
| 2706 optimized->shared()->DontAdaptArguments(); | 2719 optimized->shared()->DontAdaptArguments(); |
| 2707 JSReceiver::SetProperty(holder, key, optimized, NONE, STRICT); | 2720 JSReceiver::SetProperty(holder, key, optimized, NONE, STRICT).Assert(); |
| 2708 return optimized; | 2721 return optimized; |
| 2709 } | 2722 } |
| 2710 | 2723 |
| 2711 | 2724 |
| 2712 RUNTIME_FUNCTION(MaybeObject*, Runtime_SpecialArrayFunctions) { | 2725 RUNTIME_FUNCTION(MaybeObject*, Runtime_SpecialArrayFunctions) { |
| 2713 HandleScope scope(isolate); | 2726 HandleScope scope(isolate); |
| 2714 ASSERT(args.length() == 1); | 2727 ASSERT(args.length() == 1); |
| 2715 CONVERT_ARG_HANDLE_CHECKED(JSObject, holder, 0); | 2728 CONVERT_ARG_HANDLE_CHECKED(JSObject, holder, 0); |
| 2716 | 2729 |
| 2717 InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop); | 2730 InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop); |
| (...skipping 2440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5158 // in Object.defineProperty(). Firefox disagrees here, and actually changes | 5171 // in Object.defineProperty(). Firefox disagrees here, and actually changes |
| 5159 // the value. | 5172 // the value. |
| 5160 if (callback->IsAccessorInfo()) { | 5173 if (callback->IsAccessorInfo()) { |
| 5161 return isolate->heap()->undefined_value(); | 5174 return isolate->heap()->undefined_value(); |
| 5162 } | 5175 } |
| 5163 // Avoid redefining foreign callback as data property, just use the stored | 5176 // Avoid redefining foreign callback as data property, just use the stored |
| 5164 // setter to update the value instead. | 5177 // setter to update the value instead. |
| 5165 // TODO(mstarzinger): So far this only works if property attributes don't | 5178 // TODO(mstarzinger): So far this only works if property attributes don't |
| 5166 // change, this should be fixed once we cleanup the underlying code. | 5179 // change, this should be fixed once we cleanup the underlying code. |
| 5167 if (callback->IsForeign() && lookup.GetAttributes() == attr) { | 5180 if (callback->IsForeign() && lookup.GetAttributes() == attr) { |
| 5168 Handle<Object> result_object = | 5181 Handle<Object> result_object; |
| 5182 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 5183 isolate, result_object, |
| 5169 JSObject::SetPropertyWithCallback(js_object, | 5184 JSObject::SetPropertyWithCallback(js_object, |
| 5170 callback, | 5185 callback, |
| 5171 name, | 5186 name, |
| 5172 obj_value, | 5187 obj_value, |
| 5173 handle(lookup.holder()), | 5188 handle(lookup.holder()), |
| 5174 STRICT); | 5189 STRICT)); |
| 5175 RETURN_IF_EMPTY_HANDLE(isolate, result_object); | |
| 5176 return *result_object; | 5190 return *result_object; |
| 5177 } | 5191 } |
| 5178 } | 5192 } |
| 5179 | 5193 |
| 5180 // Take special care when attributes are different and there is already | 5194 // Take special care when attributes are different and there is already |
| 5181 // a property. For simplicity we normalize the property which enables us | 5195 // a property. For simplicity we normalize the property which enables us |
| 5182 // to not worry about changing the instance_descriptor and creating a new | 5196 // to not worry about changing the instance_descriptor and creating a new |
| 5183 // map. The current version of SetObjectProperty does not handle attributes | 5197 // map. The current version of SetObjectProperty does not handle attributes |
| 5184 // correctly in the case where a property is a field and is reset with | 5198 // correctly in the case where a property is a field and is reset with |
| 5185 // new attributes. | 5199 // new attributes. |
| 5186 if (lookup.IsFound() && | 5200 if (lookup.IsFound() && |
| 5187 (attr != lookup.GetAttributes() || lookup.IsPropertyCallbacks())) { | 5201 (attr != lookup.GetAttributes() || lookup.IsPropertyCallbacks())) { |
| 5188 // New attributes - normalize to avoid writing to instance descriptor | 5202 // New attributes - normalize to avoid writing to instance descriptor |
| 5189 if (js_object->IsJSGlobalProxy()) { | 5203 if (js_object->IsJSGlobalProxy()) { |
| 5190 // Since the result is a property, the prototype will exist so | 5204 // Since the result is a property, the prototype will exist so |
| 5191 // we don't have to check for null. | 5205 // we don't have to check for null. |
| 5192 js_object = Handle<JSObject>(JSObject::cast(js_object->GetPrototype())); | 5206 js_object = Handle<JSObject>(JSObject::cast(js_object->GetPrototype())); |
| 5193 } | 5207 } |
| 5194 JSObject::NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0); | 5208 JSObject::NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0); |
| 5195 // Use IgnoreAttributes version since a readonly property may be | 5209 // Use IgnoreAttributes version since a readonly property may be |
| 5196 // overridden and SetProperty does not allow this. | 5210 // overridden and SetProperty does not allow this. |
| 5197 Handle<Object> result = JSObject::SetLocalPropertyIgnoreAttributes( | 5211 Handle<Object> result; |
| 5198 js_object, name, obj_value, attr); | 5212 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 5199 RETURN_IF_EMPTY_HANDLE(isolate, result); | 5213 isolate, result, |
| 5214 JSObject::SetLocalPropertyIgnoreAttributes( |
| 5215 js_object, name, obj_value, attr)); |
| 5200 return *result; | 5216 return *result; |
| 5201 } | 5217 } |
| 5202 | 5218 |
| 5203 Handle<Object> result = Runtime::ForceSetObjectProperty(isolate, js_object, | 5219 Handle<Object> result; |
| 5204 name, | 5220 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 5205 obj_value, | 5221 isolate, result, |
| 5206 attr); | 5222 Runtime::ForceSetObjectProperty(js_object, name, obj_value, attr)); |
| 5207 RETURN_IF_EMPTY_HANDLE(isolate, result); | |
| 5208 return *result; | 5223 return *result; |
| 5209 } | 5224 } |
| 5210 | 5225 |
| 5211 | 5226 |
| 5212 // Return property without being observable by accessors or interceptors. | 5227 // Return property without being observable by accessors or interceptors. |
| 5213 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetDataProperty) { | 5228 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetDataProperty) { |
| 5214 SealHandleScope shs(isolate); | 5229 SealHandleScope shs(isolate); |
| 5215 ASSERT(args.length() == 2); | 5230 ASSERT(args.length() == 2); |
| 5216 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 5231 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 5217 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); | 5232 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 5232 case INTERCEPTOR: | 5247 case INTERCEPTOR: |
| 5233 break; | 5248 break; |
| 5234 case NONEXISTENT: | 5249 case NONEXISTENT: |
| 5235 UNREACHABLE(); | 5250 UNREACHABLE(); |
| 5236 } | 5251 } |
| 5237 } | 5252 } |
| 5238 return isolate->heap()->undefined_value(); | 5253 return isolate->heap()->undefined_value(); |
| 5239 } | 5254 } |
| 5240 | 5255 |
| 5241 | 5256 |
| 5242 Handle<Object> Runtime::SetObjectProperty(Isolate* isolate, | 5257 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, |
| 5243 Handle<Object> object, | 5258 Handle<Object> object, |
| 5244 Handle<Object> key, | 5259 Handle<Object> key, |
| 5245 Handle<Object> value, | 5260 Handle<Object> value, |
| 5246 PropertyAttributes attr, | 5261 PropertyAttributes attr, |
| 5247 StrictMode strict_mode) { | 5262 StrictMode strict_mode) { |
| 5248 SetPropertyMode set_mode = attr == NONE ? SET_PROPERTY : DEFINE_PROPERTY; | 5263 SetPropertyMode set_mode = attr == NONE ? SET_PROPERTY : DEFINE_PROPERTY; |
| 5249 | 5264 |
| 5250 if (object->IsUndefined() || object->IsNull()) { | 5265 if (object->IsUndefined() || object->IsNull()) { |
| 5251 Handle<Object> args[2] = { key, object }; | 5266 Handle<Object> args[2] = { key, object }; |
| 5252 Handle<Object> error = | 5267 Handle<Object> error = |
| 5253 isolate->factory()->NewTypeError("non_object_property_store", | 5268 isolate->factory()->NewTypeError("non_object_property_store", |
| 5254 HandleVector(args, 2)); | 5269 HandleVector(args, 2)); |
| 5255 isolate->Throw(*error); | 5270 isolate->Throw(*error); |
| 5256 return Handle<Object>(); | 5271 return Handle<Object>(); |
| 5257 } | 5272 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5336 if (name->AsArrayIndex(&index)) { | 5351 if (name->AsArrayIndex(&index)) { |
| 5337 return JSObject::SetElement(js_object, index, value, attr, strict_mode, | 5352 return JSObject::SetElement(js_object, index, value, attr, strict_mode, |
| 5338 true, | 5353 true, |
| 5339 set_mode); | 5354 set_mode); |
| 5340 } else { | 5355 } else { |
| 5341 return JSReceiver::SetProperty(js_object, name, value, attr, strict_mode); | 5356 return JSReceiver::SetProperty(js_object, name, value, attr, strict_mode); |
| 5342 } | 5357 } |
| 5343 } | 5358 } |
| 5344 | 5359 |
| 5345 | 5360 |
| 5346 Handle<Object> Runtime::ForceSetObjectProperty(Isolate* isolate, | 5361 MaybeHandle<Object> Runtime::ForceSetObjectProperty(Handle<JSObject> js_object, |
| 5347 Handle<JSObject> js_object, | 5362 Handle<Object> key, |
| 5348 Handle<Object> key, | 5363 Handle<Object> value, |
| 5349 Handle<Object> value, | 5364 PropertyAttributes attr) { |
| 5350 PropertyAttributes attr) { | 5365 Isolate* isolate = js_object->GetIsolate(); |
| 5351 // Check if the given key is an array index. | 5366 // Check if the given key is an array index. |
| 5352 uint32_t index; | 5367 uint32_t index; |
| 5353 if (key->ToArrayIndex(&index)) { | 5368 if (key->ToArrayIndex(&index)) { |
| 5354 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters | 5369 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters |
| 5355 // of a string using [] notation. We need to support this too in | 5370 // of a string using [] notation. We need to support this too in |
| 5356 // JavaScript. | 5371 // JavaScript. |
| 5357 // In the case of a String object we just need to redirect the assignment to | 5372 // In the case of a String object we just need to redirect the assignment to |
| 5358 // the underlying string if the index is in range. Since the underlying | 5373 // the underlying string if the index is in range. Since the underlying |
| 5359 // string does nothing with the assignment then we can ignore such | 5374 // string does nothing with the assignment then we can ignore such |
| 5360 // assignments. | 5375 // assignments. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5465 // Compute attributes. | 5480 // Compute attributes. |
| 5466 PropertyAttributes attributes = | 5481 PropertyAttributes attributes = |
| 5467 static_cast<PropertyAttributes>(unchecked_attributes); | 5482 static_cast<PropertyAttributes>(unchecked_attributes); |
| 5468 | 5483 |
| 5469 StrictMode strict_mode = SLOPPY; | 5484 StrictMode strict_mode = SLOPPY; |
| 5470 if (args.length() == 5) { | 5485 if (args.length() == 5) { |
| 5471 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode_arg, 4); | 5486 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode_arg, 4); |
| 5472 strict_mode = strict_mode_arg; | 5487 strict_mode = strict_mode_arg; |
| 5473 } | 5488 } |
| 5474 | 5489 |
| 5475 Handle<Object> result = Runtime::SetObjectProperty(isolate, object, key, | 5490 Handle<Object> result; |
| 5476 value, | 5491 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 5477 attributes, | 5492 isolate, result, |
| 5478 strict_mode); | 5493 Runtime::SetObjectProperty( |
| 5479 RETURN_IF_EMPTY_HANDLE(isolate, result); | 5494 isolate, object, key, value, attributes, strict_mode)); |
| 5480 return *result; | 5495 return *result; |
| 5481 } | 5496 } |
| 5482 | 5497 |
| 5483 | 5498 |
| 5484 RUNTIME_FUNCTION(MaybeObject*, Runtime_TransitionElementsKind) { | 5499 RUNTIME_FUNCTION(MaybeObject*, Runtime_TransitionElementsKind) { |
| 5485 HandleScope scope(isolate); | 5500 HandleScope scope(isolate); |
| 5486 RUNTIME_ASSERT(args.length() == 2); | 5501 RUNTIME_ASSERT(args.length() == 2); |
| 5487 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); | 5502 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); |
| 5488 CONVERT_ARG_HANDLE_CHECKED(Map, map, 1); | 5503 CONVERT_ARG_HANDLE_CHECKED(Map, map, 1); |
| 5489 JSObject::TransitionElementsKind(array, map->elements_kind()); | 5504 JSObject::TransitionElementsKind(array, map->elements_kind()); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5628 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 5643 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 5629 // Compute attributes. | 5644 // Compute attributes. |
| 5630 PropertyAttributes attributes = NONE; | 5645 PropertyAttributes attributes = NONE; |
| 5631 if (args.length() == 4) { | 5646 if (args.length() == 4) { |
| 5632 CONVERT_SMI_ARG_CHECKED(unchecked_value, 3); | 5647 CONVERT_SMI_ARG_CHECKED(unchecked_value, 3); |
| 5633 // Only attribute bits should be set. | 5648 // Only attribute bits should be set. |
| 5634 RUNTIME_ASSERT( | 5649 RUNTIME_ASSERT( |
| 5635 (unchecked_value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); | 5650 (unchecked_value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); |
| 5636 attributes = static_cast<PropertyAttributes>(unchecked_value); | 5651 attributes = static_cast<PropertyAttributes>(unchecked_value); |
| 5637 } | 5652 } |
| 5638 Handle<Object> result = JSObject::SetLocalPropertyIgnoreAttributes( | 5653 Handle<Object> result; |
| 5639 object, name, value, attributes); | 5654 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 5640 RETURN_IF_EMPTY_HANDLE(isolate, result); | 5655 isolate, result, |
| 5656 JSObject::SetLocalPropertyIgnoreAttributes( |
| 5657 object, name, value, attributes)); |
| 5641 return *result; | 5658 return *result; |
| 5642 } | 5659 } |
| 5643 | 5660 |
| 5644 | 5661 |
| 5645 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteProperty) { | 5662 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteProperty) { |
| 5646 HandleScope scope(isolate); | 5663 HandleScope scope(isolate); |
| 5647 ASSERT(args.length() == 3); | 5664 ASSERT(args.length() == 3); |
| 5648 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); | 5665 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); |
| 5649 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); | 5666 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); |
| 5650 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 2); | 5667 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 2); |
| (...skipping 2579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8230 } | 8247 } |
| 8231 new_bindings->set_map_no_write_barrier( | 8248 new_bindings->set_map_no_write_barrier( |
| 8232 isolate->heap()->fixed_cow_array_map()); | 8249 isolate->heap()->fixed_cow_array_map()); |
| 8233 bound_function->set_function_bindings(*new_bindings); | 8250 bound_function->set_function_bindings(*new_bindings); |
| 8234 | 8251 |
| 8235 // Update length. | 8252 // Update length. |
| 8236 Handle<String> length_string = isolate->factory()->length_string(); | 8253 Handle<String> length_string = isolate->factory()->length_string(); |
| 8237 Handle<Object> new_length(args.at<Object>(3)); | 8254 Handle<Object> new_length(args.at<Object>(3)); |
| 8238 PropertyAttributes attr = | 8255 PropertyAttributes attr = |
| 8239 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY); | 8256 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY); |
| 8240 ForceSetProperty(bound_function, length_string, new_length, attr); | 8257 Runtime::ForceSetObjectProperty( |
| 8258 bound_function, length_string, new_length, attr).Assert(); |
| 8241 return *bound_function; | 8259 return *bound_function; |
| 8242 } | 8260 } |
| 8243 | 8261 |
| 8244 | 8262 |
| 8245 RUNTIME_FUNCTION(MaybeObject*, Runtime_BoundFunctionGetBindings) { | 8263 RUNTIME_FUNCTION(MaybeObject*, Runtime_BoundFunctionGetBindings) { |
| 8246 HandleScope handles(isolate); | 8264 HandleScope handles(isolate); |
| 8247 ASSERT(args.length() == 1); | 8265 ASSERT(args.length() == 1); |
| 8248 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, callable, 0); | 8266 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, callable, 0); |
| 8249 if (callable->IsJSFunction()) { | 8267 if (callable->IsJSFunction()) { |
| 8250 Handle<JSFunction> function = Handle<JSFunction>::cast(callable); | 8268 Handle<JSFunction> function = Handle<JSFunction>::cast(callable); |
| (...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9165 Handle<AccessorInfo> info = | 9183 Handle<AccessorInfo> info = |
| 9166 Accessors::MakeModuleExport(name, index, attr); | 9184 Accessors::MakeModuleExport(name, index, attr); |
| 9167 Handle<Object> result = JSObject::SetAccessor(module, info); | 9185 Handle<Object> result = JSObject::SetAccessor(module, info); |
| 9168 ASSERT(!(result.is_null() || result->IsUndefined())); | 9186 ASSERT(!(result.is_null() || result->IsUndefined())); |
| 9169 USE(result); | 9187 USE(result); |
| 9170 break; | 9188 break; |
| 9171 } | 9189 } |
| 9172 case MODULE: { | 9190 case MODULE: { |
| 9173 Object* referenced_context = Context::cast(host_context)->get(index); | 9191 Object* referenced_context = Context::cast(host_context)->get(index); |
| 9174 Handle<JSModule> value(Context::cast(referenced_context)->module()); | 9192 Handle<JSModule> value(Context::cast(referenced_context)->module()); |
| 9175 JSReceiver::SetProperty(module, name, value, FROZEN, STRICT); | 9193 JSReceiver::SetProperty(module, name, value, FROZEN, STRICT).Assert(); |
| 9176 break; | 9194 break; |
| 9177 } | 9195 } |
| 9178 case INTERNAL: | 9196 case INTERNAL: |
| 9179 case TEMPORARY: | 9197 case TEMPORARY: |
| 9180 case DYNAMIC: | 9198 case DYNAMIC: |
| 9181 case DYNAMIC_GLOBAL: | 9199 case DYNAMIC_GLOBAL: |
| 9182 case DYNAMIC_LOCAL: | 9200 case DYNAMIC_LOCAL: |
| 9183 UNREACHABLE(); | 9201 UNREACHABLE(); |
| 9184 } | 9202 } |
| 9185 } | 9203 } |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9452 return isolate->Throw(*error); | 9470 return isolate->Throw(*error); |
| 9453 } | 9471 } |
| 9454 // In sloppy mode, the property is added to the global object. | 9472 // In sloppy mode, the property is added to the global object. |
| 9455 attributes = NONE; | 9473 attributes = NONE; |
| 9456 object = Handle<JSReceiver>(isolate->context()->global_object()); | 9474 object = Handle<JSReceiver>(isolate->context()->global_object()); |
| 9457 } | 9475 } |
| 9458 | 9476 |
| 9459 // Set the property if it's not read only or doesn't yet exist. | 9477 // Set the property if it's not read only or doesn't yet exist. |
| 9460 if ((attributes & READ_ONLY) == 0 || | 9478 if ((attributes & READ_ONLY) == 0 || |
| 9461 (JSReceiver::GetLocalPropertyAttribute(object, name) == ABSENT)) { | 9479 (JSReceiver::GetLocalPropertyAttribute(object, name) == ABSENT)) { |
| 9462 RETURN_IF_EMPTY_HANDLE( | 9480 RETURN_FAILURE_ON_EXCEPTION( |
| 9463 isolate, | 9481 isolate, |
| 9464 JSReceiver::SetProperty(object, name, value, NONE, strict_mode)); | 9482 JSReceiver::SetProperty(object, name, value, NONE, strict_mode)); |
| 9465 } else if (strict_mode == STRICT && (attributes & READ_ONLY) != 0) { | 9483 } else if (strict_mode == STRICT && (attributes & READ_ONLY) != 0) { |
| 9466 // Setting read only property in strict mode. | 9484 // Setting read only property in strict mode. |
| 9467 Handle<Object> error = | 9485 Handle<Object> error = |
| 9468 isolate->factory()->NewTypeError( | 9486 isolate->factory()->NewTypeError( |
| 9469 "strict_cannot_assign", HandleVector(&name, 1)); | 9487 "strict_cannot_assign", HandleVector(&name, 1)); |
| 9470 return isolate->Throw(*error); | 9488 return isolate->Throw(*error); |
| 9471 } | 9489 } |
| 9472 return *value; | 9490 return *value; |
| (...skipping 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11437 static bool ParameterIsShadowedByContextLocal(Handle<ScopeInfo> info, | 11455 static bool ParameterIsShadowedByContextLocal(Handle<ScopeInfo> info, |
| 11438 int index) { | 11456 int index) { |
| 11439 VariableMode mode; | 11457 VariableMode mode; |
| 11440 InitializationFlag flag; | 11458 InitializationFlag flag; |
| 11441 return info->ContextSlotIndex(info->ParameterName(index), &mode, &flag) != -1; | 11459 return info->ContextSlotIndex(info->ParameterName(index), &mode, &flag) != -1; |
| 11442 } | 11460 } |
| 11443 | 11461 |
| 11444 | 11462 |
| 11445 // Create a plain JSObject which materializes the local scope for the specified | 11463 // Create a plain JSObject which materializes the local scope for the specified |
| 11446 // frame. | 11464 // frame. |
| 11447 static Handle<JSObject> MaterializeStackLocalsWithFrameInspector( | 11465 MUST_USE_RESULT |
| 11466 static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector( |
| 11448 Isolate* isolate, | 11467 Isolate* isolate, |
| 11449 Handle<JSObject> target, | 11468 Handle<JSObject> target, |
| 11450 Handle<JSFunction> function, | 11469 Handle<JSFunction> function, |
| 11451 FrameInspector* frame_inspector) { | 11470 FrameInspector* frame_inspector) { |
| 11452 Handle<SharedFunctionInfo> shared(function->shared()); | 11471 Handle<SharedFunctionInfo> shared(function->shared()); |
| 11453 Handle<ScopeInfo> scope_info(shared->scope_info()); | 11472 Handle<ScopeInfo> scope_info(shared->scope_info()); |
| 11454 | 11473 |
| 11455 // First fill all parameters. | 11474 // First fill all parameters. |
| 11456 for (int i = 0; i < scope_info->ParameterCount(); ++i) { | 11475 for (int i = 0; i < scope_info->ParameterCount(); ++i) { |
| 11457 // Do not materialize the parameter if it is shadowed by a context local. | 11476 // Do not materialize the parameter if it is shadowed by a context local. |
| 11458 if (ParameterIsShadowedByContextLocal(scope_info, i)) continue; | 11477 if (ParameterIsShadowedByContextLocal(scope_info, i)) continue; |
| 11459 | 11478 |
| 11460 HandleScope scope(isolate); | 11479 HandleScope scope(isolate); |
| 11461 Handle<Object> value(i < frame_inspector->GetParametersCount() | 11480 Handle<Object> value(i < frame_inspector->GetParametersCount() |
| 11462 ? frame_inspector->GetParameter(i) | 11481 ? frame_inspector->GetParameter(i) |
| 11463 : isolate->heap()->undefined_value(), | 11482 : isolate->heap()->undefined_value(), |
| 11464 isolate); | 11483 isolate); |
| 11465 ASSERT(!value->IsTheHole()); | 11484 ASSERT(!value->IsTheHole()); |
| 11466 Handle<String> name(scope_info->ParameterName(i)); | 11485 Handle<String> name(scope_info->ParameterName(i)); |
| 11467 | 11486 |
| 11468 RETURN_IF_EMPTY_HANDLE_VALUE( | 11487 RETURN_ON_EXCEPTION( |
| 11469 isolate, | 11488 isolate, |
| 11470 Runtime::SetObjectProperty(isolate, target, name, value, NONE, SLOPPY), | 11489 Runtime::SetObjectProperty(isolate, target, name, value, NONE, SLOPPY), |
| 11471 Handle<JSObject>()); | 11490 JSObject); |
| 11472 } | 11491 } |
| 11473 | 11492 |
| 11474 // Second fill all stack locals. | 11493 // Second fill all stack locals. |
| 11475 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { | 11494 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { |
| 11476 Handle<String> name(scope_info->StackLocalName(i)); | 11495 Handle<String> name(scope_info->StackLocalName(i)); |
| 11477 Handle<Object> value(frame_inspector->GetExpression(i), isolate); | 11496 Handle<Object> value(frame_inspector->GetExpression(i), isolate); |
| 11478 if (value->IsTheHole()) continue; | 11497 if (value->IsTheHole()) continue; |
| 11479 | 11498 |
| 11480 RETURN_IF_EMPTY_HANDLE_VALUE( | 11499 RETURN_ON_EXCEPTION( |
| 11481 isolate, | 11500 isolate, |
| 11482 Runtime::SetObjectProperty(isolate, target, name, value, NONE, SLOPPY), | 11501 Runtime::SetObjectProperty(isolate, target, name, value, NONE, SLOPPY), |
| 11483 Handle<JSObject>()); | 11502 JSObject); |
| 11484 } | 11503 } |
| 11485 | 11504 |
| 11486 return target; | 11505 return target; |
| 11487 } | 11506 } |
| 11488 | 11507 |
| 11489 | 11508 |
| 11490 static void UpdateStackLocalsFromMaterializedObject(Isolate* isolate, | 11509 static void UpdateStackLocalsFromMaterializedObject(Isolate* isolate, |
| 11491 Handle<JSObject> target, | 11510 Handle<JSObject> target, |
| 11492 Handle<JSFunction> function, | 11511 Handle<JSFunction> function, |
| 11493 JavaScriptFrame* frame, | 11512 JavaScriptFrame* frame, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 11518 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { | 11537 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { |
| 11519 if (frame->GetExpression(i)->IsTheHole()) continue; | 11538 if (frame->GetExpression(i)->IsTheHole()) continue; |
| 11520 HandleScope scope(isolate); | 11539 HandleScope scope(isolate); |
| 11521 Handle<Object> value = Object::GetPropertyOrElement( | 11540 Handle<Object> value = Object::GetPropertyOrElement( |
| 11522 target, Handle<String>(scope_info->StackLocalName(i))); | 11541 target, Handle<String>(scope_info->StackLocalName(i))); |
| 11523 frame->SetExpression(i, *value); | 11542 frame->SetExpression(i, *value); |
| 11524 } | 11543 } |
| 11525 } | 11544 } |
| 11526 | 11545 |
| 11527 | 11546 |
| 11528 static Handle<JSObject> MaterializeLocalContext(Isolate* isolate, | 11547 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeLocalContext( |
| 11529 Handle<JSObject> target, | 11548 Isolate* isolate, |
| 11530 Handle<JSFunction> function, | 11549 Handle<JSObject> target, |
| 11531 JavaScriptFrame* frame) { | 11550 Handle<JSFunction> function, |
| 11551 JavaScriptFrame* frame) { |
| 11532 HandleScope scope(isolate); | 11552 HandleScope scope(isolate); |
| 11533 Handle<SharedFunctionInfo> shared(function->shared()); | 11553 Handle<SharedFunctionInfo> shared(function->shared()); |
| 11534 Handle<ScopeInfo> scope_info(shared->scope_info()); | 11554 Handle<ScopeInfo> scope_info(shared->scope_info()); |
| 11535 | 11555 |
| 11536 if (!scope_info->HasContext()) return target; | 11556 if (!scope_info->HasContext()) return target; |
| 11537 | 11557 |
| 11538 // Third fill all context locals. | 11558 // Third fill all context locals. |
| 11539 Handle<Context> frame_context(Context::cast(frame->context())); | 11559 Handle<Context> frame_context(Context::cast(frame->context())); |
| 11540 Handle<Context> function_context(frame_context->declaration_context()); | 11560 Handle<Context> function_context(frame_context->declaration_context()); |
| 11541 if (!ScopeInfo::CopyContextLocalsToScopeObject( | 11561 if (!ScopeInfo::CopyContextLocalsToScopeObject( |
| 11542 scope_info, function_context, target)) { | 11562 scope_info, function_context, target)) { |
| 11543 return Handle<JSObject>(); | 11563 return MaybeHandle<JSObject>(); |
| 11544 } | 11564 } |
| 11545 | 11565 |
| 11546 // Finally copy any properties from the function context extension. | 11566 // Finally copy any properties from the function context extension. |
| 11547 // These will be variables introduced by eval. | 11567 // These will be variables introduced by eval. |
| 11548 if (function_context->closure() == *function) { | 11568 if (function_context->closure() == *function) { |
| 11549 if (function_context->has_extension() && | 11569 if (function_context->has_extension() && |
| 11550 !function_context->IsNativeContext()) { | 11570 !function_context->IsNativeContext()) { |
| 11551 Handle<JSObject> ext(JSObject::cast(function_context->extension())); | 11571 Handle<JSObject> ext(JSObject::cast(function_context->extension())); |
| 11552 bool threw = false; | 11572 bool threw = false; |
| 11553 Handle<FixedArray> keys = | 11573 Handle<FixedArray> keys = |
| 11554 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw); | 11574 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw); |
| 11555 if (threw) return Handle<JSObject>(); | 11575 if (threw) return Handle<JSObject>(); |
| 11556 | 11576 |
| 11557 for (int i = 0; i < keys->length(); i++) { | 11577 for (int i = 0; i < keys->length(); i++) { |
| 11558 // Names of variables introduced by eval are strings. | 11578 // Names of variables introduced by eval are strings. |
| 11559 ASSERT(keys->get(i)->IsString()); | 11579 ASSERT(keys->get(i)->IsString()); |
| 11560 Handle<String> key(String::cast(keys->get(i))); | 11580 Handle<String> key(String::cast(keys->get(i))); |
| 11561 RETURN_IF_EMPTY_HANDLE_VALUE( | 11581 RETURN_ON_EXCEPTION( |
| 11562 isolate, | 11582 isolate, |
| 11563 Runtime::SetObjectProperty(isolate, | 11583 Runtime::SetObjectProperty(isolate, |
| 11564 target, | 11584 target, |
| 11565 key, | 11585 key, |
| 11566 Object::GetPropertyOrElement(ext, key), | 11586 Object::GetPropertyOrElement(ext, key), |
| 11567 NONE, | 11587 NONE, |
| 11568 SLOPPY), | 11588 SLOPPY), |
| 11569 Handle<JSObject>()); | 11589 JSObject); |
| 11570 } | 11590 } |
| 11571 } | 11591 } |
| 11572 } | 11592 } |
| 11573 | 11593 |
| 11574 return target; | 11594 return target; |
| 11575 } | 11595 } |
| 11576 | 11596 |
| 11577 | 11597 |
| 11578 static Handle<JSObject> MaterializeLocalScope( | 11598 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeLocalScope( |
| 11579 Isolate* isolate, | 11599 Isolate* isolate, |
| 11580 JavaScriptFrame* frame, | 11600 JavaScriptFrame* frame, |
| 11581 int inlined_jsframe_index) { | 11601 int inlined_jsframe_index) { |
| 11582 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); | 11602 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); |
| 11583 Handle<JSFunction> function(JSFunction::cast(frame_inspector.GetFunction())); | 11603 Handle<JSFunction> function(JSFunction::cast(frame_inspector.GetFunction())); |
| 11584 | 11604 |
| 11585 Handle<JSObject> local_scope = | 11605 Handle<JSObject> local_scope = |
| 11586 isolate->factory()->NewJSObject(isolate->object_function()); | 11606 isolate->factory()->NewJSObject(isolate->object_function()); |
| 11587 local_scope = MaterializeStackLocalsWithFrameInspector( | 11607 ASSIGN_RETURN_ON_EXCEPTION( |
| 11588 isolate, local_scope, function, &frame_inspector); | 11608 isolate, local_scope, |
| 11589 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, local_scope, Handle<JSObject>()); | 11609 MaterializeStackLocalsWithFrameInspector( |
| 11610 isolate, local_scope, function, &frame_inspector), |
| 11611 JSObject); |
| 11590 | 11612 |
| 11591 return MaterializeLocalContext(isolate, local_scope, function, frame); | 11613 return MaterializeLocalContext(isolate, local_scope, function, frame); |
| 11592 } | 11614 } |
| 11593 | 11615 |
| 11594 | 11616 |
| 11595 // Set the context local variable value. | 11617 // Set the context local variable value. |
| 11596 static bool SetContextLocalValue(Isolate* isolate, | 11618 static bool SetContextLocalValue(Isolate* isolate, |
| 11597 Handle<ScopeInfo> scope_info, | 11619 Handle<ScopeInfo> scope_info, |
| 11598 Handle<Context> context, | 11620 Handle<Context> context, |
| 11599 Handle<String> variable_name, | 11621 Handle<String> variable_name, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11659 // Function context extension. These are variables introduced by eval. | 11681 // Function context extension. These are variables introduced by eval. |
| 11660 if (function_context->closure() == *function) { | 11682 if (function_context->closure() == *function) { |
| 11661 if (function_context->has_extension() && | 11683 if (function_context->has_extension() && |
| 11662 !function_context->IsNativeContext()) { | 11684 !function_context->IsNativeContext()) { |
| 11663 Handle<JSObject> ext(JSObject::cast(function_context->extension())); | 11685 Handle<JSObject> ext(JSObject::cast(function_context->extension())); |
| 11664 | 11686 |
| 11665 if (JSReceiver::HasProperty(ext, variable_name)) { | 11687 if (JSReceiver::HasProperty(ext, variable_name)) { |
| 11666 // We don't expect this to do anything except replacing | 11688 // We don't expect this to do anything except replacing |
| 11667 // property value. | 11689 // property value. |
| 11668 Runtime::SetObjectProperty(isolate, ext, variable_name, new_value, | 11690 Runtime::SetObjectProperty(isolate, ext, variable_name, new_value, |
| 11669 NONE, SLOPPY); | 11691 NONE, SLOPPY).Assert(); |
| 11670 return true; | 11692 return true; |
| 11671 } | 11693 } |
| 11672 } | 11694 } |
| 11673 } | 11695 } |
| 11674 } | 11696 } |
| 11675 | 11697 |
| 11676 return default_result; | 11698 return default_result; |
| 11677 } | 11699 } |
| 11678 | 11700 |
| 11679 | 11701 |
| 11680 // Create a plain JSObject which materializes the closure content for the | 11702 // Create a plain JSObject which materializes the closure content for the |
| 11681 // context. | 11703 // context. |
| 11682 static Handle<JSObject> MaterializeClosure(Isolate* isolate, | 11704 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeClosure( |
| 11683 Handle<Context> context) { | 11705 Isolate* isolate, |
| 11706 Handle<Context> context) { |
| 11684 ASSERT(context->IsFunctionContext()); | 11707 ASSERT(context->IsFunctionContext()); |
| 11685 | 11708 |
| 11686 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 11709 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
| 11687 Handle<ScopeInfo> scope_info(shared->scope_info()); | 11710 Handle<ScopeInfo> scope_info(shared->scope_info()); |
| 11688 | 11711 |
| 11689 // Allocate and initialize a JSObject with all the content of this function | 11712 // Allocate and initialize a JSObject with all the content of this function |
| 11690 // closure. | 11713 // closure. |
| 11691 Handle<JSObject> closure_scope = | 11714 Handle<JSObject> closure_scope = |
| 11692 isolate->factory()->NewJSObject(isolate->object_function()); | 11715 isolate->factory()->NewJSObject(isolate->object_function()); |
| 11693 | 11716 |
| 11694 // Fill all context locals to the context extension. | 11717 // Fill all context locals to the context extension. |
| 11695 if (!ScopeInfo::CopyContextLocalsToScopeObject( | 11718 if (!ScopeInfo::CopyContextLocalsToScopeObject( |
| 11696 scope_info, context, closure_scope)) { | 11719 scope_info, context, closure_scope)) { |
| 11697 return Handle<JSObject>(); | 11720 return MaybeHandle<JSObject>(); |
| 11698 } | 11721 } |
| 11699 | 11722 |
| 11700 // Finally copy any properties from the function context extension. This will | 11723 // Finally copy any properties from the function context extension. This will |
| 11701 // be variables introduced by eval. | 11724 // be variables introduced by eval. |
| 11702 if (context->has_extension()) { | 11725 if (context->has_extension()) { |
| 11703 Handle<JSObject> ext(JSObject::cast(context->extension())); | 11726 Handle<JSObject> ext(JSObject::cast(context->extension())); |
| 11704 bool threw = false; | 11727 bool threw = false; |
| 11705 Handle<FixedArray> keys = | 11728 Handle<FixedArray> keys = |
| 11706 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw); | 11729 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw); |
| 11707 if (threw) return Handle<JSObject>(); | 11730 if (threw) return Handle<JSObject>(); |
| 11708 | 11731 |
| 11709 for (int i = 0; i < keys->length(); i++) { | 11732 for (int i = 0; i < keys->length(); i++) { |
| 11710 // Names of variables introduced by eval are strings. | 11733 // Names of variables introduced by eval are strings. |
| 11711 ASSERT(keys->get(i)->IsString()); | 11734 ASSERT(keys->get(i)->IsString()); |
| 11712 Handle<String> key(String::cast(keys->get(i))); | 11735 Handle<String> key(String::cast(keys->get(i))); |
| 11713 RETURN_IF_EMPTY_HANDLE_VALUE( | 11736 RETURN_ON_EXCEPTION( |
| 11714 isolate, | 11737 isolate, |
| 11715 Runtime::SetObjectProperty(isolate, closure_scope, key, | 11738 Runtime::SetObjectProperty(isolate, closure_scope, key, |
| 11716 Object::GetPropertyOrElement(ext, key), | 11739 Object::GetPropertyOrElement(ext, key), |
| 11717 NONE, SLOPPY), | 11740 NONE, SLOPPY), |
| 11718 Handle<JSObject>()); | 11741 JSObject); |
| 11719 } | 11742 } |
| 11720 } | 11743 } |
| 11721 | 11744 |
| 11722 return closure_scope; | 11745 return closure_scope; |
| 11723 } | 11746 } |
| 11724 | 11747 |
| 11725 | 11748 |
| 11726 // This method copies structure of MaterializeClosure method above. | 11749 // This method copies structure of MaterializeClosure method above. |
| 11727 static bool SetClosureVariableValue(Isolate* isolate, | 11750 static bool SetClosureVariableValue(Isolate* isolate, |
| 11728 Handle<Context> context, | 11751 Handle<Context> context, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 11739 return true; | 11762 return true; |
| 11740 } | 11763 } |
| 11741 | 11764 |
| 11742 // Properties from the function context extension. This will | 11765 // Properties from the function context extension. This will |
| 11743 // be variables introduced by eval. | 11766 // be variables introduced by eval. |
| 11744 if (context->has_extension()) { | 11767 if (context->has_extension()) { |
| 11745 Handle<JSObject> ext(JSObject::cast(context->extension())); | 11768 Handle<JSObject> ext(JSObject::cast(context->extension())); |
| 11746 if (JSReceiver::HasProperty(ext, variable_name)) { | 11769 if (JSReceiver::HasProperty(ext, variable_name)) { |
| 11747 // We don't expect this to do anything except replacing property value. | 11770 // We don't expect this to do anything except replacing property value. |
| 11748 Runtime::SetObjectProperty(isolate, ext, variable_name, new_value, | 11771 Runtime::SetObjectProperty(isolate, ext, variable_name, new_value, |
| 11749 NONE, SLOPPY); | 11772 NONE, SLOPPY).Assert(); |
| 11750 return true; | 11773 return true; |
| 11751 } | 11774 } |
| 11752 } | 11775 } |
| 11753 | 11776 |
| 11754 return false; | 11777 return false; |
| 11755 } | 11778 } |
| 11756 | 11779 |
| 11757 | 11780 |
| 11758 // Create a plain JSObject which materializes the scope for the specified | 11781 // Create a plain JSObject which materializes the scope for the specified |
| 11759 // catch context. | 11782 // catch context. |
| 11760 static Handle<JSObject> MaterializeCatchScope(Isolate* isolate, | 11783 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeCatchScope( |
| 11761 Handle<Context> context) { | 11784 Isolate* isolate, |
| 11785 Handle<Context> context) { |
| 11762 ASSERT(context->IsCatchContext()); | 11786 ASSERT(context->IsCatchContext()); |
| 11763 Handle<String> name(String::cast(context->extension())); | 11787 Handle<String> name(String::cast(context->extension())); |
| 11764 Handle<Object> thrown_object(context->get(Context::THROWN_OBJECT_INDEX), | 11788 Handle<Object> thrown_object(context->get(Context::THROWN_OBJECT_INDEX), |
| 11765 isolate); | 11789 isolate); |
| 11766 Handle<JSObject> catch_scope = | 11790 Handle<JSObject> catch_scope = |
| 11767 isolate->factory()->NewJSObject(isolate->object_function()); | 11791 isolate->factory()->NewJSObject(isolate->object_function()); |
| 11768 RETURN_IF_EMPTY_HANDLE_VALUE( | 11792 RETURN_ON_EXCEPTION( |
| 11769 isolate, | 11793 isolate, |
| 11770 Runtime::SetObjectProperty(isolate, catch_scope, name, thrown_object, | 11794 Runtime::SetObjectProperty(isolate, catch_scope, name, thrown_object, |
| 11771 NONE, SLOPPY), | 11795 NONE, SLOPPY), |
| 11772 Handle<JSObject>()); | 11796 JSObject); |
| 11773 return catch_scope; | 11797 return catch_scope; |
| 11774 } | 11798 } |
| 11775 | 11799 |
| 11776 | 11800 |
| 11777 static bool SetCatchVariableValue(Isolate* isolate, | 11801 static bool SetCatchVariableValue(Isolate* isolate, |
| 11778 Handle<Context> context, | 11802 Handle<Context> context, |
| 11779 Handle<String> variable_name, | 11803 Handle<String> variable_name, |
| 11780 Handle<Object> new_value) { | 11804 Handle<Object> new_value) { |
| 11781 ASSERT(context->IsCatchContext()); | 11805 ASSERT(context->IsCatchContext()); |
| 11782 Handle<String> name(String::cast(context->extension())); | 11806 Handle<String> name(String::cast(context->extension())); |
| 11783 if (!name->Equals(*variable_name)) { | 11807 if (!name->Equals(*variable_name)) { |
| 11784 return false; | 11808 return false; |
| 11785 } | 11809 } |
| 11786 context->set(Context::THROWN_OBJECT_INDEX, *new_value); | 11810 context->set(Context::THROWN_OBJECT_INDEX, *new_value); |
| 11787 return true; | 11811 return true; |
| 11788 } | 11812 } |
| 11789 | 11813 |
| 11790 | 11814 |
| 11791 // Create a plain JSObject which materializes the block scope for the specified | 11815 // Create a plain JSObject which materializes the block scope for the specified |
| 11792 // block context. | 11816 // block context. |
| 11793 static Handle<JSObject> MaterializeBlockScope( | 11817 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeBlockScope( |
| 11794 Isolate* isolate, | 11818 Isolate* isolate, |
| 11795 Handle<Context> context) { | 11819 Handle<Context> context) { |
| 11796 ASSERT(context->IsBlockContext()); | 11820 ASSERT(context->IsBlockContext()); |
| 11797 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); | 11821 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); |
| 11798 | 11822 |
| 11799 // Allocate and initialize a JSObject with all the arguments, stack locals | 11823 // Allocate and initialize a JSObject with all the arguments, stack locals |
| 11800 // heap locals and extension properties of the debugged function. | 11824 // heap locals and extension properties of the debugged function. |
| 11801 Handle<JSObject> block_scope = | 11825 Handle<JSObject> block_scope = |
| 11802 isolate->factory()->NewJSObject(isolate->object_function()); | 11826 isolate->factory()->NewJSObject(isolate->object_function()); |
| 11803 | 11827 |
| 11804 // Fill all context locals. | 11828 // Fill all context locals. |
| 11805 if (!ScopeInfo::CopyContextLocalsToScopeObject( | 11829 if (!ScopeInfo::CopyContextLocalsToScopeObject( |
| 11806 scope_info, context, block_scope)) { | 11830 scope_info, context, block_scope)) { |
| 11807 return Handle<JSObject>(); | 11831 return MaybeHandle<JSObject>(); |
| 11808 } | 11832 } |
| 11809 | 11833 |
| 11810 return block_scope; | 11834 return block_scope; |
| 11811 } | 11835 } |
| 11812 | 11836 |
| 11813 | 11837 |
| 11814 // Create a plain JSObject which materializes the module scope for the specified | 11838 // Create a plain JSObject which materializes the module scope for the specified |
| 11815 // module context. | 11839 // module context. |
| 11816 static Handle<JSObject> MaterializeModuleScope( | 11840 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeModuleScope( |
| 11817 Isolate* isolate, | 11841 Isolate* isolate, |
| 11818 Handle<Context> context) { | 11842 Handle<Context> context) { |
| 11819 ASSERT(context->IsModuleContext()); | 11843 ASSERT(context->IsModuleContext()); |
| 11820 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); | 11844 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); |
| 11821 | 11845 |
| 11822 // Allocate and initialize a JSObject with all the members of the debugged | 11846 // Allocate and initialize a JSObject with all the members of the debugged |
| 11823 // module. | 11847 // module. |
| 11824 Handle<JSObject> module_scope = | 11848 Handle<JSObject> module_scope = |
| 11825 isolate->factory()->NewJSObject(isolate->object_function()); | 11849 isolate->factory()->NewJSObject(isolate->object_function()); |
| 11826 | 11850 |
| 11827 // Fill all context locals. | 11851 // Fill all context locals. |
| 11828 if (!ScopeInfo::CopyContextLocalsToScopeObject( | 11852 if (!ScopeInfo::CopyContextLocalsToScopeObject( |
| 11829 scope_info, context, module_scope)) { | 11853 scope_info, context, module_scope)) { |
| 11830 return Handle<JSObject>(); | 11854 return MaybeHandle<JSObject>(); |
| 11831 } | 11855 } |
| 11832 | 11856 |
| 11833 return module_scope; | 11857 return module_scope; |
| 11834 } | 11858 } |
| 11835 | 11859 |
| 11836 | 11860 |
| 11837 // Iterate over the actual scopes visible from a stack frame or from a closure. | 11861 // Iterate over the actual scopes visible from a stack frame or from a closure. |
| 11838 // The iteration proceeds from the innermost visible nested scope outwards. | 11862 // The iteration proceeds from the innermost visible nested scope outwards. |
| 11839 // All scopes are backed by an actual context except the local scope, | 11863 // All scopes are backed by an actual context except the local scope, |
| 11840 // which is inserted "artificially" in the context chain. | 11864 // which is inserted "artificially" in the context chain. |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12030 return ScopeTypeBlock; | 12054 return ScopeTypeBlock; |
| 12031 } | 12055 } |
| 12032 if (context_->IsModuleContext()) { | 12056 if (context_->IsModuleContext()) { |
| 12033 return ScopeTypeModule; | 12057 return ScopeTypeModule; |
| 12034 } | 12058 } |
| 12035 ASSERT(context_->IsWithContext()); | 12059 ASSERT(context_->IsWithContext()); |
| 12036 return ScopeTypeWith; | 12060 return ScopeTypeWith; |
| 12037 } | 12061 } |
| 12038 | 12062 |
| 12039 // Return the JavaScript object with the content of the current scope. | 12063 // Return the JavaScript object with the content of the current scope. |
| 12040 Handle<JSObject> ScopeObject() { | 12064 MaybeHandle<JSObject> ScopeObject() { |
| 12041 ASSERT(!failed_); | 12065 ASSERT(!failed_); |
| 12042 switch (Type()) { | 12066 switch (Type()) { |
| 12043 case ScopeIterator::ScopeTypeGlobal: | 12067 case ScopeIterator::ScopeTypeGlobal: |
| 12044 return Handle<JSObject>(CurrentContext()->global_object()); | 12068 return Handle<JSObject>(CurrentContext()->global_object()); |
| 12045 case ScopeIterator::ScopeTypeLocal: | 12069 case ScopeIterator::ScopeTypeLocal: |
| 12046 // Materialize the content of the local scope into a JSObject. | 12070 // Materialize the content of the local scope into a JSObject. |
| 12047 ASSERT(nested_scope_chain_.length() == 1); | 12071 ASSERT(nested_scope_chain_.length() == 1); |
| 12048 return MaterializeLocalScope(isolate_, frame_, inlined_jsframe_index_); | 12072 return MaterializeLocalScope(isolate_, frame_, inlined_jsframe_index_); |
| 12049 case ScopeIterator::ScopeTypeWith: | 12073 case ScopeIterator::ScopeTypeWith: |
| 12050 // Return the with object. | 12074 // Return the with object. |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12307 } | 12331 } |
| 12308 return *array; | 12332 return *array; |
| 12309 } | 12333 } |
| 12310 | 12334 |
| 12311 | 12335 |
| 12312 static const int kScopeDetailsTypeIndex = 0; | 12336 static const int kScopeDetailsTypeIndex = 0; |
| 12313 static const int kScopeDetailsObjectIndex = 1; | 12337 static const int kScopeDetailsObjectIndex = 1; |
| 12314 static const int kScopeDetailsSize = 2; | 12338 static const int kScopeDetailsSize = 2; |
| 12315 | 12339 |
| 12316 | 12340 |
| 12317 static Handle<JSObject> MaterializeScopeDetails(Isolate* isolate, | 12341 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeScopeDetails( |
| 12342 Isolate* isolate, |
| 12318 ScopeIterator* it) { | 12343 ScopeIterator* it) { |
| 12319 // Calculate the size of the result. | 12344 // Calculate the size of the result. |
| 12320 int details_size = kScopeDetailsSize; | 12345 int details_size = kScopeDetailsSize; |
| 12321 Handle<FixedArray> details = isolate->factory()->NewFixedArray(details_size); | 12346 Handle<FixedArray> details = isolate->factory()->NewFixedArray(details_size); |
| 12322 | 12347 |
| 12323 // Fill in scope details. | 12348 // Fill in scope details. |
| 12324 details->set(kScopeDetailsTypeIndex, Smi::FromInt(it->Type())); | 12349 details->set(kScopeDetailsTypeIndex, Smi::FromInt(it->Type())); |
| 12325 Handle<JSObject> scope_object = it->ScopeObject(); | 12350 Handle<JSObject> scope_object; |
| 12326 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, scope_object, Handle<JSObject>()); | 12351 ASSIGN_RETURN_ON_EXCEPTION( |
| 12352 isolate, scope_object, it->ScopeObject(), JSObject); |
| 12327 details->set(kScopeDetailsObjectIndex, *scope_object); | 12353 details->set(kScopeDetailsObjectIndex, *scope_object); |
| 12328 | 12354 |
| 12329 return isolate->factory()->NewJSArrayWithElements(details); | 12355 return isolate->factory()->NewJSArrayWithElements(details); |
| 12330 } | 12356 } |
| 12331 | 12357 |
| 12332 | 12358 |
| 12333 // Return an array with scope details | 12359 // Return an array with scope details |
| 12334 // args[0]: number: break id | 12360 // args[0]: number: break id |
| 12335 // args[1]: number: frame index | 12361 // args[1]: number: frame index |
| 12336 // args[2]: number: inlined frame index | 12362 // args[2]: number: inlined frame index |
| (...skipping 23 matching lines...) Expand all Loading... |
| 12360 | 12386 |
| 12361 // Find the requested scope. | 12387 // Find the requested scope. |
| 12362 int n = 0; | 12388 int n = 0; |
| 12363 ScopeIterator it(isolate, frame, inlined_jsframe_index); | 12389 ScopeIterator it(isolate, frame, inlined_jsframe_index); |
| 12364 for (; !it.Done() && n < index; it.Next()) { | 12390 for (; !it.Done() && n < index; it.Next()) { |
| 12365 n++; | 12391 n++; |
| 12366 } | 12392 } |
| 12367 if (it.Done()) { | 12393 if (it.Done()) { |
| 12368 return isolate->heap()->undefined_value(); | 12394 return isolate->heap()->undefined_value(); |
| 12369 } | 12395 } |
| 12370 Handle<JSObject> details = MaterializeScopeDetails(isolate, &it); | 12396 Handle<JSObject> details; |
| 12371 RETURN_IF_EMPTY_HANDLE(isolate, details); | 12397 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 12398 isolate, details, MaterializeScopeDetails(isolate, &it)); |
| 12372 return *details; | 12399 return *details; |
| 12373 } | 12400 } |
| 12374 | 12401 |
| 12375 | 12402 |
| 12376 // Return an array of scope details | 12403 // Return an array of scope details |
| 12377 // args[0]: number: break id | 12404 // args[0]: number: break id |
| 12378 // args[1]: number: frame index | 12405 // args[1]: number: frame index |
| 12379 // args[2]: number: inlined frame index | 12406 // args[2]: number: inlined frame index |
| 12380 // args[3]: boolean: ignore nested scopes | 12407 // args[3]: boolean: ignore nested scopes |
| 12381 // | 12408 // |
| (...skipping 20 matching lines...) Expand all Loading... |
| 12402 } | 12429 } |
| 12403 | 12430 |
| 12404 // Get the frame where the debugging is performed. | 12431 // Get the frame where the debugging is performed. |
| 12405 StackFrame::Id id = UnwrapFrameId(wrapped_id); | 12432 StackFrame::Id id = UnwrapFrameId(wrapped_id); |
| 12406 JavaScriptFrameIterator frame_it(isolate, id); | 12433 JavaScriptFrameIterator frame_it(isolate, id); |
| 12407 JavaScriptFrame* frame = frame_it.frame(); | 12434 JavaScriptFrame* frame = frame_it.frame(); |
| 12408 | 12435 |
| 12409 List<Handle<JSObject> > result(4); | 12436 List<Handle<JSObject> > result(4); |
| 12410 ScopeIterator it(isolate, frame, inlined_jsframe_index, ignore_nested_scopes); | 12437 ScopeIterator it(isolate, frame, inlined_jsframe_index, ignore_nested_scopes); |
| 12411 for (; !it.Done(); it.Next()) { | 12438 for (; !it.Done(); it.Next()) { |
| 12412 Handle<JSObject> details = MaterializeScopeDetails(isolate, &it); | 12439 Handle<JSObject> details; |
| 12413 RETURN_IF_EMPTY_HANDLE(isolate, details); | 12440 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 12441 isolate, details, MaterializeScopeDetails(isolate, &it)); |
| 12414 result.Add(details); | 12442 result.Add(details); |
| 12415 } | 12443 } |
| 12416 | 12444 |
| 12417 Handle<FixedArray> array = isolate->factory()->NewFixedArray(result.length()); | 12445 Handle<FixedArray> array = isolate->factory()->NewFixedArray(result.length()); |
| 12418 for (int i = 0; i < result.length(); ++i) { | 12446 for (int i = 0; i < result.length(); ++i) { |
| 12419 array->set(i, *result[i]); | 12447 array->set(i, *result[i]); |
| 12420 } | 12448 } |
| 12421 return *isolate->factory()->NewJSArrayWithElements(array); | 12449 return *isolate->factory()->NewJSArrayWithElements(array); |
| 12422 } | 12450 } |
| 12423 | 12451 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 12450 // Find the requested scope. | 12478 // Find the requested scope. |
| 12451 int n = 0; | 12479 int n = 0; |
| 12452 ScopeIterator it(isolate, fun); | 12480 ScopeIterator it(isolate, fun); |
| 12453 for (; !it.Done() && n < index; it.Next()) { | 12481 for (; !it.Done() && n < index; it.Next()) { |
| 12454 n++; | 12482 n++; |
| 12455 } | 12483 } |
| 12456 if (it.Done()) { | 12484 if (it.Done()) { |
| 12457 return isolate->heap()->undefined_value(); | 12485 return isolate->heap()->undefined_value(); |
| 12458 } | 12486 } |
| 12459 | 12487 |
| 12460 Handle<JSObject> details = MaterializeScopeDetails(isolate, &it); | 12488 Handle<JSObject> details; |
| 12489 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 12490 isolate, details, MaterializeScopeDetails(isolate, &it)); |
| 12461 RETURN_IF_EMPTY_HANDLE(isolate, details); | 12491 RETURN_IF_EMPTY_HANDLE(isolate, details); |
| 12462 return *details; | 12492 return *details; |
| 12463 } | 12493 } |
| 12464 | 12494 |
| 12465 | 12495 |
| 12466 static bool SetScopeVariableValue(ScopeIterator* it, int index, | 12496 static bool SetScopeVariableValue(ScopeIterator* it, int index, |
| 12467 Handle<String> variable_name, | 12497 Handle<String> variable_name, |
| 12468 Handle<Object> new_value) { | 12498 Handle<Object> new_value) { |
| 12469 for (int n = 0; !it->Done() && n < index; it->Next()) { | 12499 for (int n = 0; !it->Done() && n < index; it->Next()) { |
| 12470 n++; | 12500 n++; |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12830 RUNTIME_FUNCTION(MaybeObject*, Runtime_ClearStepping) { | 12860 RUNTIME_FUNCTION(MaybeObject*, Runtime_ClearStepping) { |
| 12831 HandleScope scope(isolate); | 12861 HandleScope scope(isolate); |
| 12832 ASSERT(args.length() == 0); | 12862 ASSERT(args.length() == 0); |
| 12833 isolate->debug()->ClearStepping(); | 12863 isolate->debug()->ClearStepping(); |
| 12834 return isolate->heap()->undefined_value(); | 12864 return isolate->heap()->undefined_value(); |
| 12835 } | 12865 } |
| 12836 | 12866 |
| 12837 | 12867 |
| 12838 // Helper function to find or create the arguments object for | 12868 // Helper function to find or create the arguments object for |
| 12839 // Runtime_DebugEvaluate. | 12869 // Runtime_DebugEvaluate. |
| 12840 static Handle<JSObject> MaterializeArgumentsObject( | 12870 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeArgumentsObject( |
| 12841 Isolate* isolate, | 12871 Isolate* isolate, |
| 12842 Handle<JSObject> target, | 12872 Handle<JSObject> target, |
| 12843 Handle<JSFunction> function) { | 12873 Handle<JSFunction> function) { |
| 12844 // Do not materialize the arguments object for eval or top-level code. | 12874 // Do not materialize the arguments object for eval or top-level code. |
| 12845 // Skip if "arguments" is already taken. | 12875 // Skip if "arguments" is already taken. |
| 12846 if (!function->shared()->is_function() || | 12876 if (!function->shared()->is_function() || |
| 12847 JSReceiver::HasLocalProperty(target, | 12877 JSReceiver::HasLocalProperty(target, |
| 12848 isolate->factory()->arguments_string())) { | 12878 isolate->factory()->arguments_string())) { |
| 12849 return target; | 12879 return target; |
| 12850 } | 12880 } |
| 12851 | 12881 |
| 12852 // FunctionGetArguments can't throw an exception. | 12882 // FunctionGetArguments can't throw an exception. |
| 12853 Handle<JSObject> arguments = Handle<JSObject>::cast( | 12883 Handle<JSObject> arguments = Handle<JSObject>::cast( |
| 12854 Accessors::FunctionGetArguments(function)); | 12884 Accessors::FunctionGetArguments(function)); |
| 12855 Runtime::SetObjectProperty(isolate, target, | 12885 Handle<String> arguments_str = isolate->factory()->arguments_string(); |
| 12856 isolate->factory()->arguments_string(), | 12886 RETURN_ON_EXCEPTION( |
| 12857 arguments, | 12887 isolate, |
| 12858 ::NONE, | 12888 Runtime::SetObjectProperty( |
| 12859 SLOPPY); | 12889 isolate, target, arguments_str, arguments, ::NONE, SLOPPY), |
| 12890 JSObject); |
| 12860 return target; | 12891 return target; |
| 12861 } | 12892 } |
| 12862 | 12893 |
| 12863 | 12894 |
| 12864 // Compile and evaluate source for the given context. | 12895 // Compile and evaluate source for the given context. |
| 12865 static MaybeObject* DebugEvaluate(Isolate* isolate, | 12896 static MaybeObject* DebugEvaluate(Isolate* isolate, |
| 12866 Handle<Context> context, | 12897 Handle<Context> context, |
| 12867 Handle<Object> context_extension, | 12898 Handle<Object> context_extension, |
| 12868 Handle<Object> receiver, | 12899 Handle<Object> receiver, |
| 12869 Handle<String> source) { | 12900 Handle<String> source) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12939 isolate->set_context(*(save->context())); | 12970 isolate->set_context(*(save->context())); |
| 12940 | 12971 |
| 12941 // Evaluate on the context of the frame. | 12972 // Evaluate on the context of the frame. |
| 12942 Handle<Context> context(Context::cast(frame->context())); | 12973 Handle<Context> context(Context::cast(frame->context())); |
| 12943 ASSERT(!context.is_null()); | 12974 ASSERT(!context.is_null()); |
| 12944 | 12975 |
| 12945 // Materialize stack locals and the arguments object. | 12976 // Materialize stack locals and the arguments object. |
| 12946 Handle<JSObject> materialized = | 12977 Handle<JSObject> materialized = |
| 12947 isolate->factory()->NewJSObject(isolate->object_function()); | 12978 isolate->factory()->NewJSObject(isolate->object_function()); |
| 12948 | 12979 |
| 12949 materialized = MaterializeStackLocalsWithFrameInspector( | 12980 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 12950 isolate, materialized, function, &frame_inspector); | 12981 isolate, materialized, |
| 12951 RETURN_IF_EMPTY_HANDLE(isolate, materialized); | 12982 MaterializeStackLocalsWithFrameInspector( |
| 12983 isolate, materialized, function, &frame_inspector)); |
| 12952 | 12984 |
| 12953 materialized = MaterializeArgumentsObject(isolate, materialized, function); | 12985 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 12954 RETURN_IF_EMPTY_HANDLE(isolate, materialized); | 12986 isolate, materialized, |
| 12987 MaterializeArgumentsObject(isolate, materialized, function)); |
| 12955 | 12988 |
| 12956 // Add the materialized object in a with-scope to shadow the stack locals. | 12989 // Add the materialized object in a with-scope to shadow the stack locals. |
| 12957 context = isolate->factory()->NewWithContext(function, context, materialized); | 12990 context = isolate->factory()->NewWithContext(function, context, materialized); |
| 12958 | 12991 |
| 12959 Handle<Object> receiver(frame->receiver(), isolate); | 12992 Handle<Object> receiver(frame->receiver(), isolate); |
| 12960 Object* evaluate_result_object; | 12993 Object* evaluate_result_object; |
| 12961 { MaybeObject* maybe_result = | 12994 { MaybeObject* maybe_result = |
| 12962 DebugEvaluate(isolate, context, context_extension, receiver, source); | 12995 DebugEvaluate(isolate, context, context_extension, receiver, source); |
| 12963 if (!maybe_result->ToObject(&evaluate_result_object)) return maybe_result; | 12996 if (!maybe_result->ToObject(&evaluate_result_object)) return maybe_result; |
| 12964 } | 12997 } |
| (...skipping 2260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15225 } | 15258 } |
| 15226 } | 15259 } |
| 15227 | 15260 |
| 15228 | 15261 |
| 15229 void Runtime::OutOfMemory() { | 15262 void Runtime::OutOfMemory() { |
| 15230 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); | 15263 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); |
| 15231 UNREACHABLE(); | 15264 UNREACHABLE(); |
| 15232 } | 15265 } |
| 15233 | 15266 |
| 15234 } } // namespace v8::internal | 15267 } } // namespace v8::internal |
| OLD | NEW |