Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 1451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1462 // should have been a const redeclaration error when declaring | 1462 // should have been a const redeclaration error when declaring |
| 1463 // the const property. | 1463 // the const property. |
| 1464 ASSERT(!holder.is_identical_to(context)); | 1464 ASSERT(!holder.is_identical_to(context)); |
| 1465 if ((attributes & READ_ONLY) == 0) { | 1465 if ((attributes & READ_ONLY) == 0) { |
| 1466 Handle<Context>::cast(holder)->set(index, *value); | 1466 Handle<Context>::cast(holder)->set(index, *value); |
| 1467 } | 1467 } |
| 1468 } else { | 1468 } else { |
| 1469 // The holder is an arguments object. | 1469 // The holder is an arguments object. |
| 1470 ASSERT((attributes & READ_ONLY) == 0); | 1470 ASSERT((attributes & READ_ONLY) == 0); |
| 1471 Handle<JSObject> arguments(Handle<JSObject>::cast(holder)); | 1471 Handle<JSObject> arguments(Handle<JSObject>::cast(holder)); |
| 1472 SetElement(arguments, index, value); | 1472 Handle<Object> result = SetElement(arguments, index, value); |
| 1473 if (result.is_null()) return Failure::Exception(); | |
|
antonm
2011/03/02 20:28:47
you may use RETURN_IF_EMPTY_HANDLE
| |
| 1473 } | 1474 } |
| 1474 return *value; | 1475 return *value; |
| 1475 } | 1476 } |
| 1476 | 1477 |
| 1477 // The property could not be found, we introduce it in the global | 1478 // The property could not be found, we introduce it in the global |
| 1478 // context. | 1479 // context. |
| 1479 if (attributes == ABSENT) { | 1480 if (attributes == ABSENT) { |
| 1480 Handle<JSObject> global = Handle<JSObject>(Top::context()->global()); | 1481 Handle<JSObject> global = Handle<JSObject>(Top::context()->global()); |
| 1481 // Strict mode not needed (const disallowed in strict mode). | 1482 // Strict mode not needed (const disallowed in strict mode). |
| 1482 RETURN_IF_EMPTY_HANDLE( | 1483 RETURN_IF_EMPTY_HANDLE( |
| (...skipping 7169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8652 uint32_t index1, index2; | 8653 uint32_t index1, index2; |
| 8653 if (!key1->ToArrayIndex(&index1) | 8654 if (!key1->ToArrayIndex(&index1) |
| 8654 || !key2->ToArrayIndex(&index2)) { | 8655 || !key2->ToArrayIndex(&index2)) { |
| 8655 return Top::ThrowIllegalOperation(); | 8656 return Top::ThrowIllegalOperation(); |
| 8656 } | 8657 } |
| 8657 | 8658 |
| 8658 Handle<JSObject> jsobject = Handle<JSObject>::cast(object); | 8659 Handle<JSObject> jsobject = Handle<JSObject>::cast(object); |
| 8659 Handle<Object> tmp1 = GetElement(jsobject, index1); | 8660 Handle<Object> tmp1 = GetElement(jsobject, index1); |
| 8660 Handle<Object> tmp2 = GetElement(jsobject, index2); | 8661 Handle<Object> tmp2 = GetElement(jsobject, index2); |
| 8661 | 8662 |
| 8662 SetElement(jsobject, index1, tmp2); | 8663 if (SetElement(jsobject, index1, tmp2).is_null()) { |
|
antonm
2011/03/02 20:28:47
Ditto
| |
| 8663 SetElement(jsobject, index2, tmp1); | 8664 return Failure::Exception(); |
| 8665 } | |
| 8666 if (SetElement(jsobject, index2, tmp1).is_null()) { | |
| 8667 return Failure::Exception(); | |
| 8668 } | |
| 8664 | 8669 |
| 8665 return Heap::undefined_value(); | 8670 return Heap::undefined_value(); |
| 8666 } | 8671 } |
| 8667 | 8672 |
| 8668 | 8673 |
| 8669 // Returns an array that tells you where in the [0, length) interval an array | 8674 // Returns an array that tells you where in the [0, length) interval an array |
| 8670 // might have elements. Can either return keys (positive integers) or | 8675 // might have elements. Can either return keys (positive integers) or |
| 8671 // intervals (pair of a negative integer (-start-1) followed by a | 8676 // intervals (pair of a negative integer (-start-1) followed by a |
| 8672 // positive (length)) or undefined values. | 8677 // positive (length)) or undefined values. |
| 8673 // Intervals can span over some keys that are not in the object. | 8678 // Intervals can span over some keys that are not in the object. |
| (...skipping 2585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11259 // native code offset. | 11264 // native code offset. |
| 11260 static MaybeObject* Runtime_CollectStackTrace(Arguments args) { | 11265 static MaybeObject* Runtime_CollectStackTrace(Arguments args) { |
| 11261 ASSERT_EQ(args.length(), 2); | 11266 ASSERT_EQ(args.length(), 2); |
| 11262 Handle<Object> caller = args.at<Object>(0); | 11267 Handle<Object> caller = args.at<Object>(0); |
| 11263 CONVERT_NUMBER_CHECKED(int32_t, limit, Int32, args[1]); | 11268 CONVERT_NUMBER_CHECKED(int32_t, limit, Int32, args[1]); |
| 11264 | 11269 |
| 11265 HandleScope scope; | 11270 HandleScope scope; |
| 11266 | 11271 |
| 11267 limit = Max(limit, 0); // Ensure that limit is not negative. | 11272 limit = Max(limit, 0); // Ensure that limit is not negative. |
| 11268 int initial_size = Min(limit, 10); | 11273 int initial_size = Min(limit, 10); |
| 11269 Handle<JSArray> result = Factory::NewJSArray(initial_size * 4); | 11274 Handle<FixedArray> elements = |
| 11275 Factory::NewFixedArrayWithHoles(initial_size * 4); | |
| 11270 | 11276 |
| 11271 StackFrameIterator iter; | 11277 StackFrameIterator iter; |
| 11272 // If the caller parameter is a function we skip frames until we're | 11278 // If the caller parameter is a function we skip frames until we're |
| 11273 // under it before starting to collect. | 11279 // under it before starting to collect. |
| 11274 bool seen_caller = !caller->IsJSFunction(); | 11280 bool seen_caller = !caller->IsJSFunction(); |
| 11275 int cursor = 0; | 11281 int cursor = 0; |
| 11276 int frames_seen = 0; | 11282 int frames_seen = 0; |
| 11277 while (!iter.done() && frames_seen < limit) { | 11283 while (!iter.done() && frames_seen < limit) { |
| 11278 StackFrame* raw_frame = iter.frame(); | 11284 StackFrame* raw_frame = iter.frame(); |
| 11279 if (ShowFrameInStackTrace(raw_frame, *caller, &seen_caller)) { | 11285 if (ShowFrameInStackTrace(raw_frame, *caller, &seen_caller)) { |
| 11280 frames_seen++; | 11286 frames_seen++; |
| 11281 JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame); | 11287 JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame); |
| 11282 List<FrameSummary> frames(3); // Max 2 levels of inlining. | 11288 List<FrameSummary> frames(3); // Max 2 levels of inlining. |
| 11283 frame->Summarize(&frames); | 11289 frame->Summarize(&frames); |
| 11284 for (int i = frames.length() - 1; i >= 0; i--) { | 11290 for (int i = frames.length() - 1; i >= 0; i--) { |
| 11291 if (cursor + 4 > elements->length()) { | |
| 11292 int new_capacity = JSObject::NewElementsCapacity(elements->length()); | |
| 11293 Handle<FixedArray> new_elements = | |
| 11294 Factory::NewFixedArrayWithHoles(new_capacity); | |
| 11295 for (int i = 0; i < cursor; i++) { | |
| 11296 new_elements->set(i, elements->get(i)); | |
| 11297 } | |
| 11298 elements = new_elements; | |
| 11299 } | |
| 11300 ASSERT(cursor + 4 <= elements->length()); | |
| 11301 | |
| 11285 Handle<Object> recv = frames[i].receiver(); | 11302 Handle<Object> recv = frames[i].receiver(); |
| 11286 Handle<JSFunction> fun = frames[i].function(); | 11303 Handle<JSFunction> fun = frames[i].function(); |
| 11287 Handle<Code> code = frames[i].code(); | 11304 Handle<Code> code = frames[i].code(); |
| 11288 Handle<Smi> offset(Smi::FromInt(frames[i].offset())); | 11305 Handle<Smi> offset(Smi::FromInt(frames[i].offset())); |
| 11289 FixedArray* elements = FixedArray::cast(result->elements()); | 11306 elements->set(cursor++, *recv); |
| 11290 if (cursor + 3 < elements->length()) { | 11307 elements->set(cursor++, *fun); |
| 11291 elements->set(cursor++, *recv); | 11308 elements->set(cursor++, *code); |
| 11292 elements->set(cursor++, *fun); | 11309 elements->set(cursor++, *offset); |
| 11293 elements->set(cursor++, *code); | |
| 11294 elements->set(cursor++, *offset); | |
| 11295 } else { | |
| 11296 SetElement(result, cursor++, recv); | |
| 11297 SetElement(result, cursor++, fun); | |
| 11298 SetElement(result, cursor++, code); | |
| 11299 SetElement(result, cursor++, offset); | |
| 11300 } | |
| 11301 } | 11310 } |
| 11302 } | 11311 } |
| 11303 iter.Advance(); | 11312 iter.Advance(); |
| 11304 } | 11313 } |
| 11305 | 11314 Handle<JSArray> result = Factory::NewJSArrayWithElements(elements); |
| 11306 result->set_length(Smi::FromInt(cursor)); | 11315 result->set_length(Smi::FromInt(cursor)); |
| 11307 return *result; | 11316 return *result; |
| 11308 } | 11317 } |
| 11309 | 11318 |
| 11310 | 11319 |
| 11311 // Returns V8 version as a string. | 11320 // Returns V8 version as a string. |
| 11312 static MaybeObject* Runtime_GetV8Version(Arguments args) { | 11321 static MaybeObject* Runtime_GetV8Version(Arguments args) { |
| 11313 ASSERT_EQ(args.length(), 0); | 11322 ASSERT_EQ(args.length(), 0); |
| 11314 | 11323 |
| 11315 NoHandleAllocation ha; | 11324 NoHandleAllocation ha; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11460 return message->script(); | 11469 return message->script(); |
| 11461 } | 11470 } |
| 11462 | 11471 |
| 11463 | 11472 |
| 11464 #ifdef DEBUG | 11473 #ifdef DEBUG |
| 11465 // ListNatives is ONLY used by the fuzz-natives.js in debug mode | 11474 // ListNatives is ONLY used by the fuzz-natives.js in debug mode |
| 11466 // Exclude the code in release mode. | 11475 // Exclude the code in release mode. |
| 11467 static MaybeObject* Runtime_ListNatives(Arguments args) { | 11476 static MaybeObject* Runtime_ListNatives(Arguments args) { |
| 11468 ASSERT(args.length() == 0); | 11477 ASSERT(args.length() == 0); |
| 11469 HandleScope scope; | 11478 HandleScope scope; |
| 11470 Handle<JSArray> result = Factory::NewJSArray(0); | 11479 #define COUNT_ENTRY(Name, argc, ressize) + 1 |
| 11480 int entry_count = 0 | |
| 11481 RUNTIME_FUNCTION_LIST(COUNT_ENTRY) | |
| 11482 INLINE_FUNCTION_LIST(COUNT_ENTRY) | |
| 11483 INLINE_RUNTIME_FUNCTION_LIST(COUNT_ENTRY); | |
| 11484 #undef COUNT_ENTRY | |
| 11485 Handle<FixedArray> elements = Factory::NewFixedArray(entry_count); | |
| 11471 int index = 0; | 11486 int index = 0; |
| 11472 bool inline_runtime_functions = false; | 11487 bool inline_runtime_functions = false; |
| 11473 #define ADD_ENTRY(Name, argc, ressize) \ | 11488 #define ADD_ENTRY(Name, argc, ressize) \ |
| 11474 { \ | 11489 { \ |
| 11475 HandleScope inner; \ | 11490 HandleScope inner; \ |
| 11476 Handle<String> name; \ | 11491 Handle<String> name; \ |
| 11477 /* Inline runtime functions have an underscore in front of the name. */ \ | 11492 /* Inline runtime functions have an underscore in front of the name. */ \ |
| 11478 if (inline_runtime_functions) { \ | 11493 if (inline_runtime_functions) { \ |
| 11479 name = Factory::NewStringFromAscii( \ | 11494 name = Factory::NewStringFromAscii( \ |
| 11480 Vector<const char>("_" #Name, StrLength("_" #Name))); \ | 11495 Vector<const char>("_" #Name, StrLength("_" #Name))); \ |
| 11481 } else { \ | 11496 } else { \ |
| 11482 name = Factory::NewStringFromAscii( \ | 11497 name = Factory::NewStringFromAscii( \ |
| 11483 Vector<const char>(#Name, StrLength(#Name))); \ | 11498 Vector<const char>(#Name, StrLength(#Name))); \ |
| 11484 } \ | 11499 } \ |
| 11485 Handle<JSArray> pair = Factory::NewJSArray(0); \ | 11500 Handle<FixedArray> pair_elements = Factory::NewFixedArray(2); \ |
| 11486 SetElement(pair, 0, name); \ | 11501 pair_elements->set(0, *name); \ |
| 11487 SetElement(pair, 1, Handle<Smi>(Smi::FromInt(argc))); \ | 11502 pair_elements->set(1, Smi::FromInt(argc)); \ |
| 11488 SetElement(result, index++, pair); \ | 11503 Handle<JSArray> pair = Factory::NewJSArrayWithElements(pair_elements); \ |
| 11504 elements->set(index++, *pair); \ | |
| 11489 } | 11505 } |
| 11490 inline_runtime_functions = false; | 11506 inline_runtime_functions = false; |
| 11491 RUNTIME_FUNCTION_LIST(ADD_ENTRY) | 11507 RUNTIME_FUNCTION_LIST(ADD_ENTRY) |
| 11492 inline_runtime_functions = true; | 11508 inline_runtime_functions = true; |
| 11493 INLINE_FUNCTION_LIST(ADD_ENTRY) | 11509 INLINE_FUNCTION_LIST(ADD_ENTRY) |
| 11494 INLINE_RUNTIME_FUNCTION_LIST(ADD_ENTRY) | 11510 INLINE_RUNTIME_FUNCTION_LIST(ADD_ENTRY) |
| 11495 #undef ADD_ENTRY | 11511 #undef ADD_ENTRY |
| 11512 ASSERT_EQ(index, entry_count); | |
| 11513 Handle<JSArray> result = Factory::NewJSArrayWithElements(elements); | |
| 11496 return *result; | 11514 return *result; |
| 11497 } | 11515 } |
| 11498 #endif | 11516 #endif |
| 11499 | 11517 |
| 11500 | 11518 |
| 11501 static MaybeObject* Runtime_Log(Arguments args) { | 11519 static MaybeObject* Runtime_Log(Arguments args) { |
| 11502 ASSERT(args.length() == 2); | 11520 ASSERT(args.length() == 2); |
| 11503 CONVERT_CHECKED(String, format, args[0]); | 11521 CONVERT_CHECKED(String, format, args[0]); |
| 11504 CONVERT_CHECKED(JSArray, elms, args[1]); | 11522 CONVERT_CHECKED(JSArray, elms, args[1]); |
| 11505 Vector<const char> chars = format->ToAsciiVector(); | 11523 Vector<const char> chars = format->ToAsciiVector(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11583 } else { | 11601 } else { |
| 11584 // Handle last resort GC and make sure to allow future allocations | 11602 // Handle last resort GC and make sure to allow future allocations |
| 11585 // to grow the heap without causing GCs (if possible). | 11603 // to grow the heap without causing GCs (if possible). |
| 11586 Counters::gc_last_resort_from_js.Increment(); | 11604 Counters::gc_last_resort_from_js.Increment(); |
| 11587 Heap::CollectAllGarbage(false); | 11605 Heap::CollectAllGarbage(false); |
| 11588 } | 11606 } |
| 11589 } | 11607 } |
| 11590 | 11608 |
| 11591 | 11609 |
| 11592 } } // namespace v8::internal | 11610 } } // namespace v8::internal |
| OLD | NEW |