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

Side by Side Diff: src/runtime.cc

Issue 139973004: A64: Synchronize with r15814. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime.h ('k') | src/scanner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 1414
1415 RUNTIME_FUNCTION(MaybeObject*, Runtime_MapGetSize) { 1415 RUNTIME_FUNCTION(MaybeObject*, Runtime_MapGetSize) {
1416 HandleScope scope(isolate); 1416 HandleScope scope(isolate);
1417 ASSERT(args.length() == 1); 1417 ASSERT(args.length() == 1);
1418 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); 1418 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
1419 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table())); 1419 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table()));
1420 return Smi::FromInt(table->NumberOfElements()); 1420 return Smi::FromInt(table->NumberOfElements());
1421 } 1421 }
1422 1422
1423 1423
1424 static JSWeakMap* WeakMapInitialize(Isolate* isolate, 1424 static JSWeakCollection* WeakCollectionInitialize(Isolate* isolate,
1425 Handle<JSWeakMap> weakmap) { 1425 Handle<JSWeakCollection> weak_collection) {
1426 ASSERT(weakmap->map()->inobject_properties() == 0); 1426 ASSERT(weak_collection->map()->inobject_properties() == 0);
1427 Handle<ObjectHashTable> table = isolate->factory()->NewObjectHashTable(0); 1427 Handle<ObjectHashTable> table = isolate->factory()->NewObjectHashTable(0);
1428 weakmap->set_table(*table); 1428 weak_collection->set_table(*table);
1429 weakmap->set_next(Smi::FromInt(0)); 1429 weak_collection->set_next(Smi::FromInt(0));
1430 return *weakmap; 1430 return *weak_collection;
1431 } 1431 }
1432 1432
1433 1433
1434 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapInitialize) { 1434 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionInitialize) {
1435 HandleScope scope(isolate); 1435 HandleScope scope(isolate);
1436 ASSERT(args.length() == 1); 1436 ASSERT(args.length() == 1);
1437 CONVERT_ARG_HANDLE_CHECKED(JSWeakMap, weakmap, 0); 1437 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1438 return WeakMapInitialize(isolate, weakmap); 1438 return WeakCollectionInitialize(isolate, weak_collection);
1439 } 1439 }
1440 1440
1441 1441
1442 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapGet) { 1442 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionGet) {
1443 HandleScope scope(isolate); 1443 HandleScope scope(isolate);
1444 ASSERT(args.length() == 2); 1444 ASSERT(args.length() == 2);
1445 CONVERT_ARG_HANDLE_CHECKED(JSWeakMap, weakmap, 0); 1445 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1446 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 1446 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
1447 Handle<ObjectHashTable> table(ObjectHashTable::cast(weakmap->table())); 1447 Handle<ObjectHashTable> table(
1448 ObjectHashTable::cast(weak_collection->table()));
1448 Handle<Object> lookup(table->Lookup(*key), isolate); 1449 Handle<Object> lookup(table->Lookup(*key), isolate);
1449 return lookup->IsTheHole() ? isolate->heap()->undefined_value() : *lookup; 1450 return lookup->IsTheHole() ? isolate->heap()->undefined_value() : *lookup;
1450 } 1451 }
1451 1452
1452 1453
1453 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapHas) { 1454 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionHas) {
1454 HandleScope scope(isolate); 1455 HandleScope scope(isolate);
1455 ASSERT(args.length() == 2); 1456 ASSERT(args.length() == 2);
1456 CONVERT_ARG_HANDLE_CHECKED(JSWeakMap, weakmap, 0); 1457 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1457 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 1458 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
1458 Handle<ObjectHashTable> table(ObjectHashTable::cast(weakmap->table())); 1459 Handle<ObjectHashTable> table(
1460 ObjectHashTable::cast(weak_collection->table()));
1459 Handle<Object> lookup(table->Lookup(*key), isolate); 1461 Handle<Object> lookup(table->Lookup(*key), isolate);
1460 return isolate->heap()->ToBoolean(!lookup->IsTheHole()); 1462 return isolate->heap()->ToBoolean(!lookup->IsTheHole());
1461 } 1463 }
1462 1464
1463 1465
1464 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapDelete) { 1466 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionDelete) {
1465 HandleScope scope(isolate); 1467 HandleScope scope(isolate);
1466 ASSERT(args.length() == 2); 1468 ASSERT(args.length() == 2);
1467 CONVERT_ARG_HANDLE_CHECKED(JSWeakMap, weakmap, 0); 1469 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1468 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 1470 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
1469 Handle<ObjectHashTable> table(ObjectHashTable::cast(weakmap->table())); 1471 Handle<ObjectHashTable> table(ObjectHashTable::cast(
1472 weak_collection->table()));
1470 Handle<Object> lookup(table->Lookup(*key), isolate); 1473 Handle<Object> lookup(table->Lookup(*key), isolate);
1471 Handle<ObjectHashTable> new_table = 1474 Handle<ObjectHashTable> new_table =
1472 PutIntoObjectHashTable(table, key, isolate->factory()->the_hole_value()); 1475 PutIntoObjectHashTable(table, key, isolate->factory()->the_hole_value());
1473 weakmap->set_table(*new_table); 1476 weak_collection->set_table(*new_table);
1474 return isolate->heap()->ToBoolean(!lookup->IsTheHole()); 1477 return isolate->heap()->ToBoolean(!lookup->IsTheHole());
1475 } 1478 }
1476 1479
1477 1480
1478 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapSet) { 1481 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionSet) {
1479 HandleScope scope(isolate); 1482 HandleScope scope(isolate);
1480 ASSERT(args.length() == 3); 1483 ASSERT(args.length() == 3);
1481 CONVERT_ARG_HANDLE_CHECKED(JSWeakMap, weakmap, 0); 1484 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1482 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 1485 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
1483 Handle<Object> value(args[2], isolate); 1486 Handle<Object> value(args[2], isolate);
1484 Handle<ObjectHashTable> table(ObjectHashTable::cast(weakmap->table())); 1487 Handle<ObjectHashTable> table(
1488 ObjectHashTable::cast(weak_collection->table()));
1485 Handle<ObjectHashTable> new_table = PutIntoObjectHashTable(table, key, value); 1489 Handle<ObjectHashTable> new_table = PutIntoObjectHashTable(table, key, value);
1486 weakmap->set_table(*new_table); 1490 weak_collection->set_table(*new_table);
1487 return isolate->heap()->undefined_value(); 1491 return isolate->heap()->undefined_value();
1488 } 1492 }
1489 1493
1490 1494
1491 RUNTIME_FUNCTION(MaybeObject*, Runtime_ClassOf) { 1495 RUNTIME_FUNCTION(MaybeObject*, Runtime_ClassOf) {
1492 SealHandleScope shs(isolate); 1496 SealHandleScope shs(isolate);
1493 ASSERT(args.length() == 1); 1497 ASSERT(args.length() == 1);
1494 Object* obj = args[0]; 1498 Object* obj = args[0];
1495 if (!obj->IsJSObject()) return isolate->heap()->null_value(); 1499 if (!obj->IsJSObject()) return isolate->heap()->null_value();
1496 return JSObject::cast(obj)->class_name(); 1500 return JSObject::cast(obj)->class_name();
(...skipping 3655 matching lines...) Expand 10 before | Expand all | Expand 10 after
5152 // In Firefox/SpiderMonkey, Safari and Opera you can access the 5156 // In Firefox/SpiderMonkey, Safari and Opera you can access the
5153 // characters of a string using [] notation. In the case of a 5157 // characters of a string using [] notation. In the case of a
5154 // String object we just need to redirect the deletion to the 5158 // String object we just need to redirect the deletion to the
5155 // underlying string if the index is in range. Since the 5159 // underlying string if the index is in range. Since the
5156 // underlying string does nothing with the deletion, we can ignore 5160 // underlying string does nothing with the deletion, we can ignore
5157 // such deletions. 5161 // such deletions.
5158 if (receiver->IsStringObjectWithCharacterAt(index)) { 5162 if (receiver->IsStringObjectWithCharacterAt(index)) {
5159 return isolate->heap()->true_value(); 5163 return isolate->heap()->true_value();
5160 } 5164 }
5161 5165
5162 return receiver->DeleteElement(index, mode); 5166 Handle<Object> result = JSReceiver::DeleteElement(receiver, index, mode);
5167 RETURN_IF_EMPTY_HANDLE(isolate, result);
5168 return *result;
5163 } 5169 }
5164 5170
5165 Handle<Name> name; 5171 Handle<Name> name;
5166 if (key->IsName()) { 5172 if (key->IsName()) {
5167 name = Handle<Name>::cast(key); 5173 name = Handle<Name>::cast(key);
5168 } else { 5174 } else {
5169 // Call-back into JavaScript to convert the key to a string. 5175 // Call-back into JavaScript to convert the key to a string.
5170 bool has_pending_exception = false; 5176 bool has_pending_exception = false;
5171 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); 5177 Handle<Object> converted = Execution::ToString(key, &has_pending_exception);
5172 if (has_pending_exception) return Failure::Exception(); 5178 if (has_pending_exception) return Failure::Exception();
5173 name = Handle<String>::cast(converted); 5179 name = Handle<String>::cast(converted);
5174 } 5180 }
5175 5181
5176 if (name->IsString()) Handle<String>::cast(name)->TryFlatten(); 5182 if (name->IsString()) Handle<String>::cast(name)->TryFlatten();
5177 return receiver->DeleteProperty(*name, mode); 5183 Handle<Object> result = JSReceiver::DeleteProperty(receiver, name, mode);
5184 RETURN_IF_EMPTY_HANDLE(isolate, result);
5185 return *result;
5178 } 5186 }
5179 5187
5180 5188
5181 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetProperty) { 5189 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetProperty) {
5182 SealHandleScope shs(isolate); 5190 SealHandleScope shs(isolate);
5183 RUNTIME_ASSERT(args.length() == 4 || args.length() == 5); 5191 RUNTIME_ASSERT(args.length() == 4 || args.length() == 5);
5184 5192
5185 Handle<Object> object = args.at<Object>(0); 5193 Handle<Object> object = args.at<Object>(0);
5186 Handle<Object> key = args.at<Object>(1); 5194 Handle<Object> key = args.at<Object>(1);
5187 Handle<Object> value = args.at<Object>(2); 5195 Handle<Object> value = args.at<Object>(2);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
5380 (unchecked_value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 5388 (unchecked_value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
5381 attributes = static_cast<PropertyAttributes>(unchecked_value); 5389 attributes = static_cast<PropertyAttributes>(unchecked_value);
5382 } 5390 }
5383 5391
5384 return object-> 5392 return object->
5385 SetLocalPropertyIgnoreAttributes(name, args[2], attributes); 5393 SetLocalPropertyIgnoreAttributes(name, args[2], attributes);
5386 } 5394 }
5387 5395
5388 5396
5389 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteProperty) { 5397 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteProperty) {
5390 SealHandleScope shs(isolate); 5398 HandleScope scope(isolate);
5391 ASSERT(args.length() == 3); 5399 ASSERT(args.length() == 3);
5392 5400 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0);
5393 CONVERT_ARG_CHECKED(JSReceiver, object, 0); 5401 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1);
5394 CONVERT_ARG_CHECKED(Name, key, 1);
5395 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 2); 5402 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 2);
5396 return object->DeleteProperty(key, (strict_mode == kStrictMode) 5403 JSReceiver::DeleteMode delete_mode = (strict_mode == kStrictMode)
5397 ? JSReceiver::STRICT_DELETION 5404 ? JSReceiver::STRICT_DELETION : JSReceiver::NORMAL_DELETION;
5398 : JSReceiver::NORMAL_DELETION); 5405 Handle<Object> result = JSReceiver::DeleteProperty(object, key, delete_mode);
5406 RETURN_IF_EMPTY_HANDLE(isolate, result);
5407 return *result;
5399 } 5408 }
5400 5409
5401 5410
5402 static MaybeObject* HasLocalPropertyImplementation(Isolate* isolate, 5411 static MaybeObject* HasLocalPropertyImplementation(Isolate* isolate,
5403 Handle<JSObject> object, 5412 Handle<JSObject> object,
5404 Handle<Name> key) { 5413 Handle<Name> key) {
5405 if (object->HasLocalProperty(*key)) return isolate->heap()->true_value(); 5414 if (object->HasLocalProperty(*key)) return isolate->heap()->true_value();
5406 // Handle hidden prototypes. If there's a hidden prototype above this thing 5415 // Handle hidden prototypes. If there's a hidden prototype above this thing
5407 // then we have to check it for properties, because they are supposed to 5416 // then we have to check it for properties, because they are supposed to
5408 // look like they are on this object. 5417 // look like they are on this object.
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
5947 ASSERT_EQ(static_cast<int>(subject->hash_field()), 5956 ASSERT_EQ(static_cast<int>(subject->hash_field()),
5948 static_cast<int>(hash)); 5957 static_cast<int>(hash));
5949 #endif 5958 #endif
5950 subject->set_hash_field(hash); 5959 subject->set_hash_field(hash);
5951 } 5960 }
5952 return Smi::FromInt(d); 5961 return Smi::FromInt(d);
5953 } 5962 }
5954 } 5963 }
5955 5964
5956 // Slower case. 5965 // Slower case.
5966 int flags = ALLOW_HEX;
5967 if (FLAG_harmony_numeric_literals) {
5968 // The current spec draft has not updated "ToNumber Applied to the String
5969 // Type", https://bugs.ecmascript.org/show_bug.cgi?id=1584
5970 flags |= ALLOW_OCTAL | ALLOW_BINARY;
5971 }
5957 return isolate->heap()->NumberFromDouble( 5972 return isolate->heap()->NumberFromDouble(
5958 StringToDouble(isolate->unicode_cache(), subject, ALLOW_HEX)); 5973 StringToDouble(isolate->unicode_cache(), subject, flags));
5959 } 5974 }
5960 5975
5961 5976
5962 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewString) { 5977 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewString) {
5963 SealHandleScope shs(isolate); 5978 SealHandleScope shs(isolate);
5964 CONVERT_SMI_ARG_CHECKED(length, 0); 5979 CONVERT_SMI_ARG_CHECKED(length, 0);
5965 CONVERT_BOOLEAN_ARG_CHECKED(is_one_byte, 1); 5980 CONVERT_BOOLEAN_ARG_CHECKED(is_one_byte, 1);
5966 if (length == 0) return isolate->heap()->empty_string(); 5981 if (length == 0) return isolate->heap()->empty_string();
5967 if (is_one_byte) { 5982 if (is_one_byte) {
5968 return isolate->heap()->AllocateRawOneByteString(length); 5983 return isolate->heap()->AllocateRawOneByteString(length);
(...skipping 2444 matching lines...) Expand 10 before | Expand all | Expand 10 after
8413 } 8428 }
8414 } else if (type->IsOneByteEqualTo(STATIC_ASCII_VECTOR("parallel"))) { 8429 } else if (type->IsOneByteEqualTo(STATIC_ASCII_VECTOR("parallel"))) {
8415 function->MarkForParallelRecompilation(); 8430 function->MarkForParallelRecompilation();
8416 } 8431 }
8417 } 8432 }
8418 8433
8419 return isolate->heap()->undefined_value(); 8434 return isolate->heap()->undefined_value();
8420 } 8435 }
8421 8436
8422 8437
8423 RUNTIME_FUNCTION(MaybeObject*, Runtime_NeverOptimize) { 8438 RUNTIME_FUNCTION(MaybeObject*, Runtime_NeverOptimizeFunction) {
8424 HandleScope scope(isolate); 8439 HandleScope scope(isolate);
8425 8440 ASSERT(args.length() == 1);
8426 if (args.length() == 0) { 8441 CONVERT_ARG_CHECKED(JSFunction, function, 0);
8427 // Disable optimization for the calling function. 8442 ASSERT(!function->IsOptimized());
8428 JavaScriptFrameIterator it(isolate); 8443 function->shared()->set_optimization_disabled(true);
8429 if (!it.done()) {
8430 it.frame()->function()->shared()->set_optimization_disabled(true);
8431 }
8432 return isolate->heap()->undefined_value();
8433 }
8434
8435 // Disable optimization for the functions passed.
8436 for (int i = 0; i < args.length(); i++) {
8437 CONVERT_ARG_CHECKED(JSFunction, function, i);
8438 function->shared()->set_optimization_disabled(true);
8439 }
8440 return isolate->heap()->undefined_value(); 8444 return isolate->heap()->undefined_value();
8441 } 8445 }
8442 8446
8443 8447
8444 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompleteOptimization) { 8448 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetOptimizationStatus) {
8445 HandleScope scope(isolate); 8449 HandleScope scope(isolate);
8446 ASSERT(args.length() == 1); 8450 RUNTIME_ASSERT(args.length() == 1 || args.length() == 2);
8451 if (!V8::UseCrankshaft()) {
8452 return Smi::FromInt(4); // 4 == "never".
8453 }
8454 bool sync_with_compiler_thread = true;
8455 if (args.length() == 2) {
8456 CONVERT_ARG_HANDLE_CHECKED(String, sync, 1);
8457 if (sync->IsOneByteEqualTo(STATIC_ASCII_VECTOR("no sync"))) {
8458 sync_with_compiler_thread = false;
8459 }
8460 }
8447 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 8461 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
8448 if (FLAG_parallel_recompilation && V8::UseCrankshaft()) { 8462 if (FLAG_parallel_recompilation && sync_with_compiler_thread) {
8449 // While function is in optimization pipeline, it is marked accordingly.
8450 // Note that if the debugger is activated during parallel recompilation,
8451 // the function will be marked with the lazy-recompile builtin, which is
8452 // not related to parallel recompilation.
8453 while (function->IsMarkedForParallelRecompilation() || 8463 while (function->IsMarkedForParallelRecompilation() ||
8454 function->IsInRecompileQueue() || 8464 function->IsInRecompileQueue() ||
8455 function->IsMarkedForInstallingRecompiledCode()) { 8465 function->IsMarkedForInstallingRecompiledCode()) {
8456 isolate->optimizing_compiler_thread()->InstallOptimizedFunctions(); 8466 isolate->optimizing_compiler_thread()->InstallOptimizedFunctions();
8457 OS::Sleep(50); 8467 OS::Sleep(50);
8458 } 8468 }
8459 } 8469 }
8460 return isolate->heap()->undefined_value();
8461 }
8462
8463
8464 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetOptimizationStatus) {
8465 HandleScope scope(isolate);
8466 ASSERT(args.length() == 1);
8467 if (!V8::UseCrankshaft()) {
8468 return Smi::FromInt(4); // 4 == "never".
8469 }
8470 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
8471 if (FLAG_parallel_recompilation) {
8472 if (function->IsMarkedForLazyRecompilation()) {
8473 return Smi::FromInt(5); // 5 == "parallel recompilation".
8474 }
8475 }
8476 if (FLAG_always_opt) { 8470 if (FLAG_always_opt) {
8477 // We may have always opt, but that is more best-effort than a real 8471 // We may have always opt, but that is more best-effort than a real
8478 // promise, so we still say "no" if it is not optimized. 8472 // promise, so we still say "no" if it is not optimized.
8479 return function->IsOptimized() ? Smi::FromInt(3) // 3 == "always". 8473 return function->IsOptimized() ? Smi::FromInt(3) // 3 == "always".
8480 : Smi::FromInt(2); // 2 == "no". 8474 : Smi::FromInt(2); // 2 == "no".
8481 } 8475 }
8482 if (FLAG_deopt_every_n_times) { 8476 if (FLAG_deopt_every_n_times) {
8483 return Smi::FromInt(6); // 6 == "maybe deopted". 8477 return Smi::FromInt(6); // 6 == "maybe deopted".
8484 } 8478 }
8485 return function->IsOptimized() ? Smi::FromInt(1) // 1 == "yes". 8479 return function->IsOptimized() ? Smi::FromInt(1) // 1 == "yes".
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
8532 ASSERT(frame->LookupCode() == *unoptimized); 8526 ASSERT(frame->LookupCode() == *unoptimized);
8533 ASSERT(unoptimized->contains(frame->pc())); 8527 ASSERT(unoptimized->contains(frame->pc()));
8534 8528
8535 // Use linear search of the unoptimized code's back edge table to find 8529 // Use linear search of the unoptimized code's back edge table to find
8536 // the AST id matching the PC. 8530 // the AST id matching the PC.
8537 Address start = unoptimized->instruction_start(); 8531 Address start = unoptimized->instruction_start();
8538 unsigned target_pc_offset = static_cast<unsigned>(frame->pc() - start); 8532 unsigned target_pc_offset = static_cast<unsigned>(frame->pc() - start);
8539 Address table_cursor = start + unoptimized->back_edge_table_offset(); 8533 Address table_cursor = start + unoptimized->back_edge_table_offset();
8540 uint32_t table_length = Memory::uint32_at(table_cursor); 8534 uint32_t table_length = Memory::uint32_at(table_cursor);
8541 table_cursor += kIntSize; 8535 table_cursor += kIntSize;
8542 uint8_t loop_depth = 0; 8536 uint32_t loop_depth = 0;
8543 for (unsigned i = 0; i < table_length; ++i) { 8537 for (unsigned i = 0; i < table_length; ++i) {
8544 // Table entries are (AST id, pc offset) pairs. 8538 // Table entries are (AST id, pc offset) pairs.
8545 uint32_t pc_offset = Memory::uint32_at(table_cursor + kIntSize); 8539 uint32_t pc_offset = Memory::uint32_at(table_cursor + kIntSize);
8546 if (pc_offset == target_pc_offset) { 8540 if (pc_offset == target_pc_offset) {
8547 ast_id = BailoutId(static_cast<int>(Memory::uint32_at(table_cursor))); 8541 ast_id = BailoutId(static_cast<int>(Memory::uint32_at(table_cursor)));
8548 loop_depth = Memory::uint8_at(table_cursor + 2 * kIntSize); 8542 loop_depth = Memory::uint32_at(table_cursor + 2 * kIntSize);
8549 break; 8543 break;
8550 } 8544 }
8551 table_cursor += FullCodeGenerator::kBackEdgeEntrySize; 8545 table_cursor += FullCodeGenerator::kBackEdgeEntrySize;
8552 } 8546 }
8553 ASSERT(!ast_id.IsNone()); 8547 ASSERT(!ast_id.IsNone());
8554 if (FLAG_trace_osr) { 8548 if (FLAG_trace_osr) {
8555 PrintF("[replacing on-stack at AST id %d, loop depth %d in ", 8549 PrintF("[replacing on-stack at AST id %d, loop depth %d in ",
8556 ast_id.ToInt(), loop_depth); 8550 ast_id.ToInt(), loop_depth);
8557 function->PrintName(); 8551 function->PrintName();
8558 PrintF("]\n"); 8552 PrintF("]\n");
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
8743 8737
8744 isolate->set_context(result); 8738 isolate->set_context(result);
8745 8739
8746 return result; // non-failure 8740 return result; // non-failure
8747 } 8741 }
8748 8742
8749 8743
8750 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushWithContext) { 8744 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushWithContext) {
8751 SealHandleScope shs(isolate); 8745 SealHandleScope shs(isolate);
8752 ASSERT(args.length() == 2); 8746 ASSERT(args.length() == 2);
8753 JSObject* extension_object; 8747 JSReceiver* extension_object;
8754 if (args[0]->IsJSObject()) { 8748 if (args[0]->IsJSReceiver()) {
8755 extension_object = JSObject::cast(args[0]); 8749 extension_object = JSReceiver::cast(args[0]);
8756 } else { 8750 } else {
8757 // Convert the object to a proper JavaScript object. 8751 // Convert the object to a proper JavaScript object.
8758 MaybeObject* maybe_js_object = args[0]->ToObject(); 8752 MaybeObject* maybe_js_object = args[0]->ToObject();
8759 if (!maybe_js_object->To(&extension_object)) { 8753 if (!maybe_js_object->To(&extension_object)) {
8760 if (Failure::cast(maybe_js_object)->IsInternalError()) { 8754 if (Failure::cast(maybe_js_object)->IsInternalError()) {
8761 HandleScope scope(isolate); 8755 HandleScope scope(isolate);
8762 Handle<Object> handle = args.at<Object>(0); 8756 Handle<Object> handle = args.at<Object>(0);
8763 Handle<Object> result = 8757 Handle<Object> result =
8764 isolate->factory()->NewTypeError("with_expression", 8758 isolate->factory()->NewTypeError("with_expression",
8765 HandleVector(&handle, 1)); 8759 HandleVector(&handle, 1));
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
8961 8955
8962 // If the slot was found in a context, it should be DONT_DELETE. 8956 // If the slot was found in a context, it should be DONT_DELETE.
8963 if (holder->IsContext()) { 8957 if (holder->IsContext()) {
8964 return isolate->heap()->false_value(); 8958 return isolate->heap()->false_value();
8965 } 8959 }
8966 8960
8967 // The slot was found in a JSObject, either a context extension object, 8961 // The slot was found in a JSObject, either a context extension object,
8968 // the global object, or the subject of a with. Try to delete it 8962 // the global object, or the subject of a with. Try to delete it
8969 // (respecting DONT_DELETE). 8963 // (respecting DONT_DELETE).
8970 Handle<JSObject> object = Handle<JSObject>::cast(holder); 8964 Handle<JSObject> object = Handle<JSObject>::cast(holder);
8971 return object->DeleteProperty(*name, JSReceiver::NORMAL_DELETION); 8965 Handle<Object> result = JSReceiver::DeleteProperty(object, name);
8966 RETURN_IF_EMPTY_HANDLE(isolate, result);
8967 return *result;
8972 } 8968 }
8973 8969
8974 8970
8975 // A mechanism to return a pair of Object pointers in registers (if possible). 8971 // A mechanism to return a pair of Object pointers in registers (if possible).
8976 // How this is achieved is calling convention-dependent. 8972 // How this is achieved is calling convention-dependent.
8977 // All currently supported x86 compiles uses calling conventions that are cdecl 8973 // All currently supported x86 compiles uses calling conventions that are cdecl
8978 // variants where a 64-bit value is returned in two 32-bit registers 8974 // variants where a 64-bit value is returned in two 32-bit registers
8979 // (edx:eax on ia32, r1:r0 on ARM). 8975 // (edx:eax on ia32, r1:r0 on ARM).
8980 // In AMD-64 calling convention a struct of two pointers is returned in rdx:rax. 8976 // In AMD-64 calling convention a struct of two pointers is returned in rdx:rax.
8981 // In Win64 calling convention, a struct of two pointers is returned in memory, 8977 // In Win64 calling convention, a struct of two pointers is returned in memory,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
9046 9042
9047 int index; 9043 int index;
9048 PropertyAttributes attributes; 9044 PropertyAttributes attributes;
9049 ContextLookupFlags flags = FOLLOW_CHAINS; 9045 ContextLookupFlags flags = FOLLOW_CHAINS;
9050 BindingFlags binding_flags; 9046 BindingFlags binding_flags;
9051 Handle<Object> holder = context->Lookup(name, 9047 Handle<Object> holder = context->Lookup(name,
9052 flags, 9048 flags,
9053 &index, 9049 &index,
9054 &attributes, 9050 &attributes,
9055 &binding_flags); 9051 &binding_flags);
9052 if (isolate->has_pending_exception()) {
9053 return MakePair(Failure::Exception(), NULL);
9054 }
9056 9055
9057 // If the index is non-negative, the slot has been found in a context. 9056 // If the index is non-negative, the slot has been found in a context.
9058 if (index >= 0) { 9057 if (index >= 0) {
9059 ASSERT(holder->IsContext()); 9058 ASSERT(holder->IsContext());
9060 // If the "property" we were looking for is a local variable, the 9059 // If the "property" we were looking for is a local variable, the
9061 // receiver is the global object; see ECMA-262, 3rd., 10.1.6 and 10.2.3. 9060 // receiver is the global object; see ECMA-262, 3rd., 10.1.6 and 10.2.3.
9062 // 9061 //
9063 // Use the hole as the receiver to signal that the receiver is implicit 9062 // Use the hole as the receiver to signal that the receiver is implicit
9064 // and that the global receiver should be used (as distinguished from an 9063 // and that the global receiver should be used (as distinguished from an
9065 // explicit receiver that happens to be a global object). 9064 // explicit receiver that happens to be a global object).
(...skipping 20 matching lines...) Expand all
9086 case MISSING_BINDING: 9085 case MISSING_BINDING:
9087 UNREACHABLE(); 9086 UNREACHABLE();
9088 return MakePair(NULL, NULL); 9087 return MakePair(NULL, NULL);
9089 } 9088 }
9090 } 9089 }
9091 9090
9092 // Otherwise, if the slot was found the holder is a context extension 9091 // Otherwise, if the slot was found the holder is a context extension
9093 // object, subject of a with, or a global object. We read the named 9092 // object, subject of a with, or a global object. We read the named
9094 // property from it. 9093 // property from it.
9095 if (!holder.is_null()) { 9094 if (!holder.is_null()) {
9096 Handle<JSObject> object = Handle<JSObject>::cast(holder); 9095 Handle<JSReceiver> object = Handle<JSReceiver>::cast(holder);
9097 ASSERT(object->HasProperty(*name)); 9096 ASSERT(object->IsJSProxy() || object->HasProperty(*name));
9098 // GetProperty below can cause GC. 9097 // GetProperty below can cause GC.
9099 Handle<Object> receiver_handle( 9098 Handle<Object> receiver_handle(
9100 object->IsGlobalObject() 9099 object->IsGlobalObject()
9101 ? GlobalObject::cast(*object)->global_receiver() 9100 ? GlobalObject::cast(*object)->global_receiver()
9102 : ComputeReceiverForNonGlobal(isolate, *object), 9101 : object->IsJSProxy() ? static_cast<Object*>(*object)
9102 : ComputeReceiverForNonGlobal(isolate, JSObject::cast(*object)),
9103 isolate); 9103 isolate);
9104 9104
9105 // No need to unhole the value here. This is taken care of by the 9105 // No need to unhole the value here. This is taken care of by the
9106 // GetProperty function. 9106 // GetProperty function.
9107 MaybeObject* value = object->GetProperty(*name); 9107 MaybeObject* value = object->GetProperty(*name);
9108 return MakePair(value, *receiver_handle); 9108 return MakePair(value, *receiver_handle);
9109 } 9109 }
9110 9110
9111 if (throw_error) { 9111 if (throw_error) {
9112 // The property doesn't exist - throw exception. 9112 // The property doesn't exist - throw exception.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
9145 9145
9146 int index; 9146 int index;
9147 PropertyAttributes attributes; 9147 PropertyAttributes attributes;
9148 ContextLookupFlags flags = FOLLOW_CHAINS; 9148 ContextLookupFlags flags = FOLLOW_CHAINS;
9149 BindingFlags binding_flags; 9149 BindingFlags binding_flags;
9150 Handle<Object> holder = context->Lookup(name, 9150 Handle<Object> holder = context->Lookup(name,
9151 flags, 9151 flags,
9152 &index, 9152 &index,
9153 &attributes, 9153 &attributes,
9154 &binding_flags); 9154 &binding_flags);
9155 if (isolate->has_pending_exception()) return Failure::Exception();
9155 9156
9156 if (index >= 0) { 9157 if (index >= 0) {
9157 // The property was found in a context slot. 9158 // The property was found in a context slot.
9158 Handle<Context> context = Handle<Context>::cast(holder); 9159 Handle<Context> context = Handle<Context>::cast(holder);
9159 if (binding_flags == MUTABLE_CHECK_INITIALIZED && 9160 if (binding_flags == MUTABLE_CHECK_INITIALIZED &&
9160 context->get(index)->IsTheHole()) { 9161 context->get(index)->IsTheHole()) {
9161 Handle<Object> error = 9162 Handle<Object> error =
9162 isolate->factory()->NewReferenceError("not_defined", 9163 isolate->factory()->NewReferenceError("not_defined",
9163 HandleVector(&name, 1)); 9164 HandleVector(&name, 1));
9164 return isolate->Throw(*error); 9165 return isolate->Throw(*error);
9165 } 9166 }
9166 // Ignore if read_only variable. 9167 // Ignore if read_only variable.
9167 if ((attributes & READ_ONLY) == 0) { 9168 if ((attributes & READ_ONLY) == 0) {
9168 // Context is a fixed array and set cannot fail. 9169 // Context is a fixed array and set cannot fail.
9169 context->set(index, *value); 9170 context->set(index, *value);
9170 } else if (strict_mode == kStrictMode) { 9171 } else if (strict_mode == kStrictMode) {
9171 // Setting read only property in strict mode. 9172 // Setting read only property in strict mode.
9172 Handle<Object> error = 9173 Handle<Object> error =
9173 isolate->factory()->NewTypeError("strict_cannot_assign", 9174 isolate->factory()->NewTypeError("strict_cannot_assign",
9174 HandleVector(&name, 1)); 9175 HandleVector(&name, 1));
9175 return isolate->Throw(*error); 9176 return isolate->Throw(*error);
9176 } 9177 }
9177 return *value; 9178 return *value;
9178 } 9179 }
9179 9180
9180 // Slow case: The property is not in a context slot. It is either in a 9181 // Slow case: The property is not in a context slot. It is either in a
9181 // context extension object, a property of the subject of a with, or a 9182 // context extension object, a property of the subject of a with, or a
9182 // property of the global object. 9183 // property of the global object.
9183 Handle<JSObject> object; 9184 Handle<JSReceiver> object;
9184 9185
9185 if (!holder.is_null()) { 9186 if (!holder.is_null()) {
9186 // The property exists on the holder. 9187 // The property exists on the holder.
9187 object = Handle<JSObject>::cast(holder); 9188 object = Handle<JSReceiver>::cast(holder);
9188 } else { 9189 } else {
9189 // The property was not found. 9190 // The property was not found.
9190 ASSERT(attributes == ABSENT); 9191 ASSERT(attributes == ABSENT);
9191 9192
9192 if (strict_mode == kStrictMode) { 9193 if (strict_mode == kStrictMode) {
9193 // Throw in strict mode (assignment to undefined variable). 9194 // Throw in strict mode (assignment to undefined variable).
9194 Handle<Object> error = 9195 Handle<Object> error =
9195 isolate->factory()->NewReferenceError( 9196 isolate->factory()->NewReferenceError(
9196 "not_defined", HandleVector(&name, 1)); 9197 "not_defined", HandleVector(&name, 1));
9197 return isolate->Throw(*error); 9198 return isolate->Throw(*error);
9198 } 9199 }
9199 // In non-strict mode, the property is added to the global object. 9200 // In non-strict mode, the property is added to the global object.
9200 attributes = NONE; 9201 attributes = NONE;
9201 object = Handle<JSObject>(isolate->context()->global_object()); 9202 object = Handle<JSReceiver>(isolate->context()->global_object());
9202 } 9203 }
9203 9204
9204 // Set the property if it's not read only or doesn't yet exist. 9205 // Set the property if it's not read only or doesn't yet exist.
9205 if ((attributes & READ_ONLY) == 0 || 9206 if ((attributes & READ_ONLY) == 0 ||
9206 (object->GetLocalPropertyAttribute(*name) == ABSENT)) { 9207 (object->GetLocalPropertyAttribute(*name) == ABSENT)) {
9207 RETURN_IF_EMPTY_HANDLE( 9208 RETURN_IF_EMPTY_HANDLE(
9208 isolate, 9209 isolate,
9209 JSReceiver::SetProperty(object, name, value, NONE, strict_mode)); 9210 JSReceiver::SetProperty(object, name, value, NONE, strict_mode));
9210 } else if (strict_mode == kStrictMode && (attributes & READ_ONLY) != 0) { 9211 } else if (strict_mode == kStrictMode && (attributes & READ_ONLY) != 0) {
9211 // Setting read only property in strict mode. 9212 // Setting read only property in strict mode.
(...skipping 1961 matching lines...) Expand 10 before | Expand all | Expand 10 after
11173 } 11174 }
11174 details->set(kFrameDetailsReceiverIndex, *receiver); 11175 details->set(kFrameDetailsReceiverIndex, *receiver);
11175 11176
11176 ASSERT_EQ(details_size, details_index); 11177 ASSERT_EQ(details_size, details_index);
11177 return *isolate->factory()->NewJSArrayWithElements(details); 11178 return *isolate->factory()->NewJSArrayWithElements(details);
11178 } 11179 }
11179 11180
11180 11181
11181 // Create a plain JSObject which materializes the local scope for the specified 11182 // Create a plain JSObject which materializes the local scope for the specified
11182 // frame. 11183 // frame.
11183 static Handle<JSObject> MaterializeLocalScopeWithFrameInspector( 11184 static Handle<JSObject> MaterializeStackLocalsWithFrameInspector(
11184 Isolate* isolate, 11185 Isolate* isolate,
11185 JavaScriptFrame* frame, 11186 Handle<JSObject> target,
11187 Handle<JSFunction> function,
11186 FrameInspector* frame_inspector) { 11188 FrameInspector* frame_inspector) {
11187 Handle<JSFunction> function(JSFunction::cast(frame_inspector->GetFunction()));
11188 Handle<SharedFunctionInfo> shared(function->shared()); 11189 Handle<SharedFunctionInfo> shared(function->shared());
11189 Handle<ScopeInfo> scope_info(shared->scope_info()); 11190 Handle<ScopeInfo> scope_info(shared->scope_info());
11190 11191
11191 // Allocate and initialize a JSObject with all the arguments, stack locals
11192 // heap locals and extension properties of the debugged function.
11193 Handle<JSObject> local_scope =
11194 isolate->factory()->NewJSObject(isolate->object_function());
11195
11196 // First fill all parameters. 11192 // First fill all parameters.
11197 for (int i = 0; i < scope_info->ParameterCount(); ++i) { 11193 for (int i = 0; i < scope_info->ParameterCount(); ++i) {
11198 Handle<Object> value(i < frame_inspector->GetParametersCount() 11194 Handle<Object> value(i < frame_inspector->GetParametersCount()
11199 ? frame_inspector->GetParameter(i) 11195 ? frame_inspector->GetParameter(i)
11200 : isolate->heap()->undefined_value(), 11196 : isolate->heap()->undefined_value(),
11201 isolate); 11197 isolate);
11202 11198
11203 RETURN_IF_EMPTY_HANDLE_VALUE( 11199 RETURN_IF_EMPTY_HANDLE_VALUE(
11204 isolate, 11200 isolate,
11205 SetProperty(isolate, 11201 SetProperty(isolate,
11206 local_scope, 11202 target,
11207 Handle<String>(scope_info->ParameterName(i)), 11203 Handle<String>(scope_info->ParameterName(i)),
11208 value, 11204 value,
11209 NONE, 11205 NONE,
11210 kNonStrictMode), 11206 kNonStrictMode),
11211 Handle<JSObject>()); 11207 Handle<JSObject>());
11212 } 11208 }
11213 11209
11214 // Second fill all stack locals. 11210 // Second fill all stack locals.
11215 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { 11211 for (int i = 0; i < scope_info->StackLocalCount(); ++i) {
11216 RETURN_IF_EMPTY_HANDLE_VALUE( 11212 RETURN_IF_EMPTY_HANDLE_VALUE(
11217 isolate, 11213 isolate,
11218 SetProperty(isolate, 11214 SetProperty(isolate,
11219 local_scope, 11215 target,
11220 Handle<String>(scope_info->StackLocalName(i)), 11216 Handle<String>(scope_info->StackLocalName(i)),
11221 Handle<Object>(frame_inspector->GetExpression(i), isolate), 11217 Handle<Object>(frame_inspector->GetExpression(i), isolate),
11222 NONE, 11218 NONE,
11223 kNonStrictMode), 11219 kNonStrictMode),
11224 Handle<JSObject>()); 11220 Handle<JSObject>());
11225 } 11221 }
11226 11222
11227 if (scope_info->HasContext()) { 11223 return target;
11228 // Third fill all context locals. 11224 }
11229 Handle<Context> frame_context(Context::cast(frame->context()));
11230 Handle<Context> function_context(frame_context->declaration_context());
11231 if (!scope_info->CopyContextLocalsToScopeObject(
11232 isolate, function_context, local_scope)) {
11233 return Handle<JSObject>();
11234 }
11235 11225
11236 // Finally copy any properties from the function context extension.
11237 // These will be variables introduced by eval.
11238 if (function_context->closure() == *function) {
11239 if (function_context->has_extension() &&
11240 !function_context->IsNativeContext()) {
11241 Handle<JSObject> ext(JSObject::cast(function_context->extension()));
11242 bool threw = false;
11243 Handle<FixedArray> keys =
11244 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw);
11245 if (threw) return Handle<JSObject>();
11246 11226
11247 for (int i = 0; i < keys->length(); i++) { 11227 static void UpdateStackLocalsFromMaterializedObject(Isolate* isolate,
11248 // Names of variables introduced by eval are strings. 11228 Handle<JSObject> target,
11249 ASSERT(keys->get(i)->IsString()); 11229 Handle<JSFunction> function,
11250 Handle<String> key(String::cast(keys->get(i))); 11230 JavaScriptFrame* frame,
11251 RETURN_IF_EMPTY_HANDLE_VALUE( 11231 int inlined_jsframe_index) {
11252 isolate, 11232 if (inlined_jsframe_index != 0 || frame->is_optimized()) {
11253 SetProperty(isolate, 11233 // Optimized frames are not supported.
11254 local_scope, 11234 // TODO(yangguo): make sure all code deoptimized when debugger is active
11255 key, 11235 // and assert that this cannot happen.
11256 GetProperty(isolate, ext, key), 11236 return;
11257 NONE, 11237 }
11258 kNonStrictMode), 11238
11259 Handle<JSObject>()); 11239 Handle<SharedFunctionInfo> shared(function->shared());
11260 } 11240 Handle<ScopeInfo> scope_info(shared->scope_info());
11241
11242 // Parameters.
11243 for (int i = 0; i < scope_info->ParameterCount(); ++i) {
11244 HandleScope scope(isolate);
11245 Handle<Object> value = GetProperty(
11246 isolate, target, Handle<String>(scope_info->ParameterName(i)));
11247 frame->SetParameterValue(i, *value);
11248 }
11249
11250 // Stack locals.
11251 for (int i = 0; i < scope_info->StackLocalCount(); ++i) {
11252 HandleScope scope(isolate);
11253 Handle<Object> value = GetProperty(
11254 isolate, target, Handle<String>(scope_info->StackLocalName(i)));
11255 frame->SetExpression(i, *value);
11256 }
11257 }
11258
11259
11260 static Handle<JSObject> MaterializeLocalContext(Isolate* isolate,
11261 Handle<JSObject> target,
11262 Handle<JSFunction> function,
11263 JavaScriptFrame* frame) {
11264 HandleScope scope(isolate);
11265 Handle<SharedFunctionInfo> shared(function->shared());
11266 Handle<ScopeInfo> scope_info(shared->scope_info());
11267
11268 if (!scope_info->HasContext()) return target;
11269
11270 // Third fill all context locals.
11271 Handle<Context> frame_context(Context::cast(frame->context()));
11272 Handle<Context> function_context(frame_context->declaration_context());
11273 if (!scope_info->CopyContextLocalsToScopeObject(
11274 isolate, function_context, target)) {
11275 return Handle<JSObject>();
11276 }
11277
11278 // Finally copy any properties from the function context extension.
11279 // These will be variables introduced by eval.
11280 if (function_context->closure() == *function) {
11281 if (function_context->has_extension() &&
11282 !function_context->IsNativeContext()) {
11283 Handle<JSObject> ext(JSObject::cast(function_context->extension()));
11284 bool threw = false;
11285 Handle<FixedArray> keys =
11286 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw);
11287 if (threw) return Handle<JSObject>();
11288
11289 for (int i = 0; i < keys->length(); i++) {
11290 // Names of variables introduced by eval are strings.
11291 ASSERT(keys->get(i)->IsString());
11292 Handle<String> key(String::cast(keys->get(i)));
11293 RETURN_IF_EMPTY_HANDLE_VALUE(
11294 isolate,
11295 SetProperty(isolate,
11296 target,
11297 key,
11298 GetProperty(isolate, ext, key),
11299 NONE,
11300 kNonStrictMode),
11301 Handle<JSObject>());
11261 } 11302 }
11262 } 11303 }
11263 } 11304 }
11264 11305
11265 return local_scope; 11306 return target;
11266 } 11307 }
11267 11308
11268 11309
11269 static Handle<JSObject> MaterializeLocalScope( 11310 static Handle<JSObject> MaterializeLocalScope(
11270 Isolate* isolate, 11311 Isolate* isolate,
11271 JavaScriptFrame* frame, 11312 JavaScriptFrame* frame,
11272 int inlined_jsframe_index) { 11313 int inlined_jsframe_index) {
11273 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); 11314 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate);
11274 return MaterializeLocalScopeWithFrameInspector(isolate, 11315 Handle<JSFunction> function(JSFunction::cast(frame_inspector.GetFunction()));
11275 frame, 11316
11276 &frame_inspector); 11317 Handle<JSObject> local_scope =
11318 isolate->factory()->NewJSObject(isolate->object_function());
11319 local_scope = MaterializeStackLocalsWithFrameInspector(
11320 isolate, local_scope, function, &frame_inspector);
11321 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, local_scope, Handle<JSObject>());
11322
11323 return MaterializeLocalContext(isolate, local_scope, function, frame);
11277 } 11324 }
11278 11325
11279 11326
11280 // Set the context local variable value. 11327 // Set the context local variable value.
11281 static bool SetContextLocalValue(Isolate* isolate, 11328 static bool SetContextLocalValue(Isolate* isolate,
11282 Handle<ScopeInfo> scope_info, 11329 Handle<ScopeInfo> scope_info,
11283 Handle<Context> context, 11330 Handle<Context> context,
11284 Handle<String> variable_name, 11331 Handle<String> variable_name,
11285 Handle<Object> new_value) { 11332 Handle<Object> new_value) {
11286 for (int i = 0; i < scope_info->ContextLocalCount(); i++) { 11333 for (int i = 0; i < scope_info->ContextLocalCount(); i++) {
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after
12419 12466
12420 // Clear all stepping set by PrepareStep. 12467 // Clear all stepping set by PrepareStep.
12421 RUNTIME_FUNCTION(MaybeObject*, Runtime_ClearStepping) { 12468 RUNTIME_FUNCTION(MaybeObject*, Runtime_ClearStepping) {
12422 HandleScope scope(isolate); 12469 HandleScope scope(isolate);
12423 ASSERT(args.length() == 0); 12470 ASSERT(args.length() == 0);
12424 isolate->debug()->ClearStepping(); 12471 isolate->debug()->ClearStepping();
12425 return isolate->heap()->undefined_value(); 12472 return isolate->heap()->undefined_value();
12426 } 12473 }
12427 12474
12428 12475
12429 static bool IsBlockOrCatchOrWithScope(ScopeIterator::ScopeType type) {
12430 return type == ScopeIterator::ScopeTypeBlock ||
12431 type == ScopeIterator::ScopeTypeCatch ||
12432 type == ScopeIterator::ScopeTypeWith;
12433 }
12434
12435
12436 // Creates a copy of the with context chain. The copy of the context chain is
12437 // is linked to the function context supplied.
12438 static Handle<Context> CopyNestedScopeContextChain(Isolate* isolate,
12439 Handle<JSFunction> function,
12440 Handle<Context> base,
12441 JavaScriptFrame* frame,
12442 int inlined_jsframe_index) {
12443 HandleScope scope(isolate);
12444 List<Handle<ScopeInfo> > scope_chain;
12445 List<Handle<Context> > context_chain;
12446
12447 ScopeIterator it(isolate, frame, inlined_jsframe_index);
12448 if (it.Failed()) return Handle<Context>::null();
12449
12450 for ( ; IsBlockOrCatchOrWithScope(it.Type()); it.Next()) {
12451 ASSERT(!it.Done());
12452 scope_chain.Add(it.CurrentScopeInfo());
12453 context_chain.Add(it.CurrentContext());
12454 }
12455
12456 // At the end of the chain. Return the base context to link to.
12457 Handle<Context> context = base;
12458
12459 // Iteratively copy and or materialize the nested contexts.
12460 while (!scope_chain.is_empty()) {
12461 Handle<ScopeInfo> scope_info = scope_chain.RemoveLast();
12462 Handle<Context> current = context_chain.RemoveLast();
12463 ASSERT(!(scope_info->HasContext() & current.is_null()));
12464
12465 if (scope_info->scope_type() == CATCH_SCOPE) {
12466 ASSERT(current->IsCatchContext());
12467 Handle<String> name(String::cast(current->extension()));
12468 Handle<Object> thrown_object(current->get(Context::THROWN_OBJECT_INDEX),
12469 isolate);
12470 context =
12471 isolate->factory()->NewCatchContext(function,
12472 context,
12473 name,
12474 thrown_object);
12475 } else if (scope_info->scope_type() == BLOCK_SCOPE) {
12476 // Materialize the contents of the block scope into a JSObject.
12477 ASSERT(current->IsBlockContext());
12478 Handle<JSObject> block_scope_object =
12479 MaterializeBlockScope(isolate, current);
12480 CHECK(!block_scope_object.is_null());
12481 // Allocate a new function context for the debug evaluation and set the
12482 // extension object.
12483 Handle<Context> new_context =
12484 isolate->factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS,
12485 function);
12486 new_context->set_extension(*block_scope_object);
12487 new_context->set_previous(*context);
12488 context = new_context;
12489 } else {
12490 ASSERT(scope_info->scope_type() == WITH_SCOPE);
12491 ASSERT(current->IsWithContext());
12492 Handle<JSObject> extension(JSObject::cast(current->extension()));
12493 context =
12494 isolate->factory()->NewWithContext(function, context, extension);
12495 }
12496 }
12497
12498 return scope.CloseAndEscape(context);
12499 }
12500
12501
12502 // Helper function to find or create the arguments object for 12476 // Helper function to find or create the arguments object for
12503 // Runtime_DebugEvaluate. 12477 // Runtime_DebugEvaluate.
12504 static Handle<Object> GetArgumentsObject(Isolate* isolate, 12478 static Handle<JSObject> MaterializeArgumentsObject(
12505 JavaScriptFrame* frame, 12479 Isolate* isolate,
12506 FrameInspector* frame_inspector, 12480 Handle<JSObject> target,
12507 Handle<ScopeInfo> scope_info, 12481 Handle<JSFunction> function) {
12508 Handle<Context> function_context) { 12482 // Do not materialize the arguments object for eval or top-level code.
12509 // Try to find the value of 'arguments' to pass as parameter. If it is not 12483 // Skip if "arguments" is already taken.
12510 // found (that is the debugged function does not reference 'arguments' and 12484 if (!function->shared()->is_function() ||
12511 // does not support eval) then create an 'arguments' object. 12485 target->HasLocalProperty(isolate->heap()->arguments_string())) {
12512 int index; 12486 return target;
12513 if (scope_info->StackLocalCount() > 0) {
12514 index = scope_info->StackSlotIndex(isolate->heap()->arguments_string());
12515 if (index != -1) {
12516 return Handle<Object>(frame->GetExpression(index), isolate);
12517 }
12518 } 12487 }
12519 12488
12520 if (scope_info->HasHeapAllocatedLocals()) { 12489 // FunctionGetArguments can't throw an exception.
12521 VariableMode mode; 12490 Handle<JSObject> arguments = Handle<JSObject>::cast(
12522 InitializationFlag init_flag; 12491 Accessors::FunctionGetArguments(function));
12523 index = scope_info->ContextSlotIndex( 12492 SetProperty(isolate,
12524 isolate->heap()->arguments_string(), &mode, &init_flag); 12493 target,
12525 if (index != -1) { 12494 isolate->factory()->arguments_string(),
12526 return Handle<Object>(function_context->get(index), isolate); 12495 arguments,
12527 } 12496 ::NONE,
12528 } 12497 kNonStrictMode);
12529 12498 return target;
12530 // FunctionGetArguments can't return a non-Object.
12531 return Handle<JSObject>(JSObject::cast(
12532 Accessors::FunctionGetArguments(frame_inspector->GetFunction(),
12533 NULL)->ToObjectUnchecked()), isolate);
12534 } 12499 }
12535 12500
12536 12501
12537 // Compile and evaluate source for the given context. 12502 // Compile and evaluate source for the given context.
12538 static MaybeObject* DebugEvaluate(Isolate* isolate, 12503 static MaybeObject* DebugEvaluate(Isolate* isolate,
12539 Handle<Context> context, 12504 Handle<Context> context,
12540 Handle<Object> context_extension, 12505 Handle<Object> context_extension,
12541 Handle<Object> receiver, 12506 Handle<Object> receiver,
12542 Handle<String> source) { 12507 Handle<String> source) {
12543 if (context_extension->IsJSObject()) { 12508 if (context_extension->IsJSObject()) {
(...skipping 26 matching lines...) Expand all
12570 result = Handle<JSObject>(JSObject::cast(result->GetPrototype(isolate))); 12535 result = Handle<JSObject>(JSObject::cast(result->GetPrototype(isolate)));
12571 } 12536 }
12572 12537
12573 // Clear the oneshot breakpoints so that the debugger does not step further. 12538 // Clear the oneshot breakpoints so that the debugger does not step further.
12574 isolate->debug()->ClearStepping(); 12539 isolate->debug()->ClearStepping();
12575 return *result; 12540 return *result;
12576 } 12541 }
12577 12542
12578 12543
12579 // Evaluate a piece of JavaScript in the context of a stack frame for 12544 // Evaluate a piece of JavaScript in the context of a stack frame for
12580 // debugging. This is done by creating a new context which in its extension 12545 // debugging. Things that need special attention are:
12581 // part has all the parameters and locals of the function on the stack frame 12546 // - Parameters and stack-allocated locals need to be materialized. Altered
12582 // as well as a materialized arguments object. As this context replaces 12547 // values need to be written back to the stack afterwards.
12583 // the context of the function on the stack frame a new (empty) function 12548 // - The arguments object needs to materialized.
12584 // is created as well to be used as the closure for the context.
12585 // This closure as replacements for the one on the stack frame presenting
12586 // the same view of the values of parameters and local variables as if the
12587 // piece of JavaScript was evaluated at the point where the function on the
12588 // stack frame is currently stopped when we compile and run the (direct) eval.
12589 // Returns array of
12590 // #0: evaluate result
12591 // #1: local variables materizalized again as object after evaluation, contain
12592 // original variable values as they remained on stack
12593 // #2: local variables materizalized as object before evaluation (and possibly
12594 // modified by expression having been executed)
12595 // Since user expression only reaches (and modifies) copies of local variables,
12596 // those copies are returned to the caller to allow tracking the changes and
12597 // manually updating the actual variables.
12598 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugEvaluate) { 12549 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugEvaluate) {
12599 HandleScope scope(isolate); 12550 HandleScope scope(isolate);
12600 12551
12601 // Check the execution state and decode arguments frame and source to be 12552 // Check the execution state and decode arguments frame and source to be
12602 // evaluated. 12553 // evaluated.
12603 ASSERT(args.length() == 6); 12554 ASSERT(args.length() == 6);
12604 Object* check_result; 12555 Object* check_result;
12605 { MaybeObject* maybe_result = Runtime_CheckExecutionState( 12556 { MaybeObject* maybe_result = Runtime_CheckExecutionState(
12606 RUNTIME_ARGUMENTS(isolate, args)); 12557 RUNTIME_ARGUMENTS(isolate, args));
12607 if (!maybe_result->ToObject(&check_result)) return maybe_result; 12558 if (!maybe_result->ToObject(&check_result)) return maybe_result;
(...skipping 14 matching lines...) Expand all
12622 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); 12573 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate);
12623 Handle<JSFunction> function(JSFunction::cast(frame_inspector.GetFunction())); 12574 Handle<JSFunction> function(JSFunction::cast(frame_inspector.GetFunction()));
12624 12575
12625 // Traverse the saved contexts chain to find the active context for the 12576 // Traverse the saved contexts chain to find the active context for the
12626 // selected frame. 12577 // selected frame.
12627 SaveContext* save = FindSavedContextForFrame(isolate, frame); 12578 SaveContext* save = FindSavedContextForFrame(isolate, frame);
12628 12579
12629 SaveContext savex(isolate); 12580 SaveContext savex(isolate);
12630 isolate->set_context(*(save->context())); 12581 isolate->set_context(*(save->context()));
12631 12582
12632 // Create the (empty) function replacing the function on the stack frame for 12583 // Evaluate on the context of the frame.
12633 // the purpose of evaluating in the context created below. It is important 12584 Handle<Context> context(Context::cast(frame->context()));
12634 // that this function does not describe any parameters and local variables 12585 ASSERT(!context.is_null());
12635 // in the context. If it does then this will cause problems with the lookup
12636 // in Context::Lookup, where context slots for parameters and local variables
12637 // are looked at before the extension object.
12638 Handle<JSFunction> go_between =
12639 isolate->factory()->NewFunction(isolate->factory()->empty_string(),
12640 isolate->factory()->undefined_value());
12641 go_between->set_context(function->context());
12642 #ifdef DEBUG
12643 Handle<ScopeInfo> go_between_scope_info(go_between->shared()->scope_info());
12644 ASSERT(go_between_scope_info->ParameterCount() == 0);
12645 ASSERT(go_between_scope_info->ContextLocalCount() == 0);
12646 #endif
12647 12586
12648 // Materialize the content of the local scope including the arguments object. 12587 // Materialize stack locals and the arguments object.
12649 Handle<JSObject> local_scope = MaterializeLocalScopeWithFrameInspector( 12588 Handle<JSObject> materialized =
12650 isolate, frame, &frame_inspector); 12589 isolate->factory()->NewJSObject(isolate->object_function());
12651 RETURN_IF_EMPTY_HANDLE(isolate, local_scope);
12652 12590
12653 // Do not materialize the arguments object for eval or top-level code. 12591 materialized = MaterializeStackLocalsWithFrameInspector(
12654 if (function->shared()->is_function()) { 12592 isolate, materialized, function, &frame_inspector);
12655 Handle<Context> frame_context(Context::cast(frame->context())); 12593 RETURN_IF_EMPTY_HANDLE(isolate, materialized);
12656 Handle<Context> function_context;
12657 Handle<ScopeInfo> scope_info(function->shared()->scope_info());
12658 if (scope_info->HasContext()) {
12659 function_context = Handle<Context>(frame_context->declaration_context());
12660 }
12661 Handle<Object> arguments = GetArgumentsObject(isolate,
12662 frame,
12663 &frame_inspector,
12664 scope_info,
12665 function_context);
12666 SetProperty(isolate,
12667 local_scope,
12668 isolate->factory()->arguments_string(),
12669 arguments,
12670 ::NONE,
12671 kNonStrictMode);
12672 }
12673 12594
12674 // Allocate a new context for the debug evaluation and set the extension 12595 materialized = MaterializeArgumentsObject(isolate, materialized, function);
12675 // object build. 12596 RETURN_IF_EMPTY_HANDLE(isolate, materialized);
12676 Handle<Context> context = isolate->factory()->NewFunctionContext(
12677 Context::MIN_CONTEXT_SLOTS, go_between);
12678 12597
12679 // Use the materialized local scope in a with context. 12598 // Add the materialized object in a with-scope to shadow the stack locals.
12680 context = 12599 context = isolate->factory()->NewWithContext(function, context, materialized);
12681 isolate->factory()->NewWithContext(go_between, context, local_scope);
12682
12683 // Copy any with contexts present and chain them in front of this context.
12684 context = CopyNestedScopeContextChain(isolate,
12685 go_between,
12686 context,
12687 frame,
12688 inlined_jsframe_index);
12689 if (context.is_null()) {
12690 ASSERT(isolate->has_pending_exception());
12691 MaybeObject* exception = isolate->pending_exception();
12692 isolate->clear_pending_exception();
12693 return exception;
12694 }
12695 12600
12696 Handle<Object> receiver(frame->receiver(), isolate); 12601 Handle<Object> receiver(frame->receiver(), isolate);
12697 Object* evaluate_result_object; 12602 Object* evaluate_result_object;
12698 { MaybeObject* maybe_result = 12603 { MaybeObject* maybe_result =
12699 DebugEvaluate(isolate, context, context_extension, receiver, source); 12604 DebugEvaluate(isolate, context, context_extension, receiver, source);
12700 if (!maybe_result->ToObject(&evaluate_result_object)) return maybe_result; 12605 if (!maybe_result->ToObject(&evaluate_result_object)) return maybe_result;
12701 } 12606 }
12702 Handle<Object> evaluate_result(evaluate_result_object, isolate);
12703 12607
12704 Handle<JSObject> local_scope_control_copy = 12608 Handle<Object> result(evaluate_result_object, isolate);
12705 MaterializeLocalScopeWithFrameInspector(isolate, frame,
12706 &frame_inspector);
12707 12609
12708 Handle<FixedArray> resultArray = isolate->factory()->NewFixedArray(3); 12610 // Write back potential changes to materialized stack locals to the stack.
12709 resultArray->set(0, *evaluate_result); 12611 UpdateStackLocalsFromMaterializedObject(
12710 resultArray->set(1, *local_scope_control_copy); 12612 isolate, materialized, function, frame, inlined_jsframe_index);
12711 resultArray->set(2, *local_scope);
12712 12613
12713 return *(isolate->factory()->NewJSArrayWithElements(resultArray)); 12614 return *result;
12714 } 12615 }
12715 12616
12716 12617
12717 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugEvaluateGlobal) { 12618 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugEvaluateGlobal) {
12718 HandleScope scope(isolate); 12619 HandleScope scope(isolate);
12719 12620
12720 // Check the execution state and decode arguments frame and source to be 12621 // Check the execution state and decode arguments frame and source to be
12721 // evaluated. 12622 // evaluated.
12722 ASSERT(args.length() == 4); 12623 ASSERT(args.length() == 4);
12723 Object* check_result; 12624 Object* check_result;
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after
13873 RUNTIME_FUNCTION(MaybeObject*, Runtime_ObservationWeakMapCreate) { 13774 RUNTIME_FUNCTION(MaybeObject*, Runtime_ObservationWeakMapCreate) {
13874 HandleScope scope(isolate); 13775 HandleScope scope(isolate);
13875 ASSERT(args.length() == 0); 13776 ASSERT(args.length() == 0);
13876 // TODO(adamk): Currently this runtime function is only called three times per 13777 // TODO(adamk): Currently this runtime function is only called three times per
13877 // isolate. If it's called more often, the map should be moved into the 13778 // isolate. If it's called more often, the map should be moved into the
13878 // strong root list. 13779 // strong root list.
13879 Handle<Map> map = 13780 Handle<Map> map =
13880 isolate->factory()->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); 13781 isolate->factory()->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize);
13881 Handle<JSWeakMap> weakmap = 13782 Handle<JSWeakMap> weakmap =
13882 Handle<JSWeakMap>::cast(isolate->factory()->NewJSObjectFromMap(map)); 13783 Handle<JSWeakMap>::cast(isolate->factory()->NewJSObjectFromMap(map));
13883 return WeakMapInitialize(isolate, weakmap); 13784 return WeakCollectionInitialize(isolate, weakmap);
13884 } 13785 }
13885 13786
13886 13787
13887 RUNTIME_FUNCTION(MaybeObject*, Runtime_UnwrapGlobalProxy) { 13788 RUNTIME_FUNCTION(MaybeObject*, Runtime_UnwrapGlobalProxy) {
13888 SealHandleScope shs(isolate); 13789 SealHandleScope shs(isolate);
13889 ASSERT(args.length() == 1); 13790 ASSERT(args.length() == 1);
13890 Object* object = args[0]; 13791 Object* object = args[0];
13891 if (object->IsJSGlobalProxy()) { 13792 if (object->IsJSGlobalProxy()) {
13892 object = object->GetPrototype(isolate); 13793 object = object->GetPrototype(isolate);
13893 if (object->IsNull()) return isolate->heap()->undefined_value(); 13794 if (object->IsNull()) return isolate->heap()->undefined_value();
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
14078 // Handle last resort GC and make sure to allow future allocations 13979 // Handle last resort GC and make sure to allow future allocations
14079 // to grow the heap without causing GCs (if possible). 13980 // to grow the heap without causing GCs (if possible).
14080 isolate->counters()->gc_last_resort_from_js()->Increment(); 13981 isolate->counters()->gc_last_resort_from_js()->Increment();
14081 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13982 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14082 "Runtime::PerformGC"); 13983 "Runtime::PerformGC");
14083 } 13984 }
14084 } 13985 }
14085 13986
14086 13987
14087 } } // namespace v8::internal 13988 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698