| 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 5045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5056 return Smi::FromInt(d); | 5056 return Smi::FromInt(d); |
| 5057 } | 5057 } |
| 5058 } | 5058 } |
| 5059 | 5059 |
| 5060 // Slower case. | 5060 // Slower case. |
| 5061 return isolate->heap()->NumberFromDouble( | 5061 return isolate->heap()->NumberFromDouble( |
| 5062 StringToDouble(isolate->unicode_cache(), subject, ALLOW_HEX)); | 5062 StringToDouble(isolate->unicode_cache(), subject, ALLOW_HEX)); |
| 5063 } | 5063 } |
| 5064 | 5064 |
| 5065 | 5065 |
| 5066 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringFromCharCodeArray) { | 5066 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewString) { |
| 5067 NoHandleAllocation ha; | 5067 CONVERT_SMI_ARG_CHECKED(length, 0); |
| 5068 ASSERT(args.length() == 1); | 5068 CONVERT_BOOLEAN_ARG_CHECKED(is_one_byte, 1); |
| 5069 | 5069 if (length == 0) return isolate->heap()->empty_string(); |
| 5070 CONVERT_ARG_CHECKED(JSArray, codes, 0); | 5070 if (is_one_byte) { |
| 5071 int length = Smi::cast(codes->length())->value(); | 5071 return isolate->heap()->AllocateRawOneByteString(length); |
| 5072 | 5072 } else { |
| 5073 // Check if the string can be ASCII. | 5073 return isolate->heap()->AllocateRawTwoByteString(length); |
| 5074 int i; | |
| 5075 for (i = 0; i < length; i++) { | |
| 5076 Object* element; | |
| 5077 { MaybeObject* maybe_element = codes->GetElement(i); | |
| 5078 // We probably can't get an exception here, but just in order to enforce | |
| 5079 // the checking of inputs in the runtime calls we check here. | |
| 5080 if (!maybe_element->ToObject(&element)) return maybe_element; | |
| 5081 } | |
| 5082 CONVERT_NUMBER_CHECKED(int, chr, Int32, element); | |
| 5083 if ((chr & 0xffff) > String::kMaxAsciiCharCode) | |
| 5084 break; | |
| 5085 } | 5074 } |
| 5086 | |
| 5087 MaybeObject* maybe_object = NULL; | |
| 5088 if (i == length) { // The string is ASCII. | |
| 5089 maybe_object = isolate->heap()->AllocateRawOneByteString(length); | |
| 5090 } else { // The string is not ASCII. | |
| 5091 maybe_object = isolate->heap()->AllocateRawTwoByteString(length); | |
| 5092 } | |
| 5093 | |
| 5094 Object* object = NULL; | |
| 5095 if (!maybe_object->ToObject(&object)) return maybe_object; | |
| 5096 String* result = String::cast(object); | |
| 5097 for (int i = 0; i < length; i++) { | |
| 5098 Object* element; | |
| 5099 { MaybeObject* maybe_element = codes->GetElement(i); | |
| 5100 if (!maybe_element->ToObject(&element)) return maybe_element; | |
| 5101 } | |
| 5102 CONVERT_NUMBER_CHECKED(int, chr, Int32, element); | |
| 5103 result->Set(i, chr & 0xffff); | |
| 5104 } | |
| 5105 return result; | |
| 5106 } | 5075 } |
| 5107 | 5076 |
| 5108 | 5077 |
| 5078 RUNTIME_FUNCTION(MaybeObject*, Runtime_TruncateString) { |
| 5079 CONVERT_ARG_CHECKED(SeqString, string, 0); |
| 5080 CONVERT_SMI_ARG_CHECKED(new_length, 1); |
| 5081 RUNTIME_ASSERT(new_length <= string->length()); |
| 5082 RUNTIME_ASSERT(new_length > 0); |
| 5083 if (new_length != string->length()) string->Truncate(new_length); |
| 5084 return string; |
| 5085 } |
| 5086 |
| 5087 |
| 5109 // kNotEscaped is generated by the following: | 5088 // kNotEscaped is generated by the following: |
| 5110 // | 5089 // |
| 5111 // #!/bin/perl | 5090 // #!/bin/perl |
| 5112 // for (my $i = 0; $i < 256; $i++) { | 5091 // for (my $i = 0; $i < 256; $i++) { |
| 5113 // print "\n" if $i % 16 == 0; | 5092 // print "\n" if $i % 16 == 0; |
| 5114 // my $c = chr($i); | 5093 // my $c = chr($i); |
| 5115 // my $escaped = 1; | 5094 // my $escaped = 1; |
| 5116 // $escaped = 0 if $c =~ m#[A-Za-z0-9@*_+./-]#; | 5095 // $escaped = 0 if $c =~ m#[A-Za-z0-9@*_+./-]#; |
| 5117 // print $escaped ? "0, " : "1, "; | 5096 // print $escaped ? "0, " : "1, "; |
| 5118 // } | 5097 // } |
| (...skipping 8264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13383 // Handle last resort GC and make sure to allow future allocations | 13362 // Handle last resort GC and make sure to allow future allocations |
| 13384 // to grow the heap without causing GCs (if possible). | 13363 // to grow the heap without causing GCs (if possible). |
| 13385 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13364 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13386 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13365 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13387 "Runtime::PerformGC"); | 13366 "Runtime::PerformGC"); |
| 13388 } | 13367 } |
| 13389 } | 13368 } |
| 13390 | 13369 |
| 13391 | 13370 |
| 13392 } } // namespace v8::internal | 13371 } } // namespace v8::internal |
| OLD | NEW |