| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "factory.h" | 5 #include "factory.h" |
| 6 | 6 |
| 7 #include "isolate-inl.h" | 7 #include "isolate-inl.h" |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace internal { | 10 namespace internal { |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 327 |
| 328 Handle<ConsString> Factory::NewRawConsString(String::Encoding encoding) { | 328 Handle<ConsString> Factory::NewRawConsString(String::Encoding encoding) { |
| 329 Handle<Map> map = (encoding == String::ONE_BYTE_ENCODING) | 329 Handle<Map> map = (encoding == String::ONE_BYTE_ENCODING) |
| 330 ? cons_ascii_string_map() : cons_string_map(); | 330 ? cons_ascii_string_map() : cons_string_map(); |
| 331 CALL_HEAP_FUNCTION(isolate(), | 331 CALL_HEAP_FUNCTION(isolate(), |
| 332 isolate()->heap()->Allocate(*map, NEW_SPACE), | 332 isolate()->heap()->Allocate(*map, NEW_SPACE), |
| 333 ConsString); | 333 ConsString); |
| 334 } | 334 } |
| 335 | 335 |
| 336 | 336 |
| 337 Handle<String> Factory::NewConsString(Handle<String> left, | 337 MaybeHandle<String> Factory::NewConsString(Handle<String> left, |
| 338 Handle<String> right) { | 338 Handle<String> right) { |
| 339 int left_length = left->length(); | 339 int left_length = left->length(); |
| 340 if (left_length == 0) return right; | 340 if (left_length == 0) return right; |
| 341 int right_length = right->length(); | 341 int right_length = right->length(); |
| 342 if (right_length == 0) return left; | 342 if (right_length == 0) return left; |
| 343 | 343 |
| 344 int length = left_length + right_length; | 344 int length = left_length + right_length; |
| 345 | 345 |
| 346 if (length == 2) { | 346 if (length == 2) { |
| 347 uint16_t c1 = left->Get(0); | 347 uint16_t c1 = left->Get(0); |
| 348 uint16_t c2 = right->Get(0); | 348 uint16_t c2 = right->Get(0); |
| 349 return MakeOrFindTwoCharacterString(isolate(), c1, c2); | 349 return MakeOrFindTwoCharacterString(isolate(), c1, c2); |
| 350 } | 350 } |
| 351 | 351 |
| 352 // Make sure that an out of memory exception is thrown if the length | 352 // Make sure that an out of memory exception is thrown if the length |
| 353 // of the new cons string is too large. | 353 // of the new cons string is too large. |
| 354 if (length > String::kMaxLength || length < 0) { | 354 if (length > String::kMaxLength || length < 0) { |
| 355 isolate()->ThrowInvalidStringLength(); | 355 return isolate()->Throw<String>( |
| 356 return Handle<String>::null(); | 356 isolate()->factory()->NewInvalidStringLengthError()); |
| 357 } | 357 } |
| 358 | 358 |
| 359 bool left_is_one_byte = left->IsOneByteRepresentation(); | 359 bool left_is_one_byte = left->IsOneByteRepresentation(); |
| 360 bool right_is_one_byte = right->IsOneByteRepresentation(); | 360 bool right_is_one_byte = right->IsOneByteRepresentation(); |
| 361 bool is_one_byte = left_is_one_byte && right_is_one_byte; | 361 bool is_one_byte = left_is_one_byte && right_is_one_byte; |
| 362 bool is_one_byte_data_in_two_byte_string = false; | 362 bool is_one_byte_data_in_two_byte_string = false; |
| 363 if (!is_one_byte) { | 363 if (!is_one_byte) { |
| 364 // At least one of the strings uses two-byte representation so we | 364 // At least one of the strings uses two-byte representation so we |
| 365 // can't use the fast case code for short ASCII strings below, but | 365 // can't use the fast case code for short ASCII strings below, but |
| 366 // we can try to save memory if all chars actually fit in ASCII. | 366 // we can try to save memory if all chars actually fit in ASCII. |
| (...skipping 1576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1943 if (name->Equals(h->infinity_string())) return infinity_value(); | 1943 if (name->Equals(h->infinity_string())) return infinity_value(); |
| 1944 return Handle<Object>::null(); | 1944 return Handle<Object>::null(); |
| 1945 } | 1945 } |
| 1946 | 1946 |
| 1947 | 1947 |
| 1948 Handle<Object> Factory::ToBoolean(bool value) { | 1948 Handle<Object> Factory::ToBoolean(bool value) { |
| 1949 return value ? true_value() : false_value(); | 1949 return value ? true_value() : false_value(); |
| 1950 } | 1950 } |
| 1951 | 1951 |
| 1952 } } // namespace v8::internal | 1952 } } // namespace v8::internal |
| OLD | NEW |