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 "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/debug.h" | 9 #include "src/debug.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
11 #include "src/runtime/runtime.h" | 11 #include "src/runtime/runtime.h" |
12 #include "src/runtime/runtime-utils.h" | 12 #include "src/runtime/runtime-utils.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 // Returns a single character string where first character equals | 17 // Returns a single character string where first character equals |
18 // string->Get(index). | 18 // string->Get(index). |
19 static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) { | 19 static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) { |
20 if (index < static_cast<uint32_t>(string->length())) { | 20 DCHECK_LT(index, static_cast<uint32_t>(string->length())); |
21 Factory* factory = string->GetIsolate()->factory(); | 21 Factory* factory = string->GetIsolate()->factory(); |
22 return factory->LookupSingleCharacterStringFromCode( | 22 return factory->LookupSingleCharacterStringFromCode( |
23 String::Flatten(string)->Get(index)); | 23 String::Flatten(string)->Get(index)); |
24 } | |
25 return Execution::CharAt(string, index); | |
26 } | 24 } |
27 | 25 |
28 | 26 |
29 MaybeHandle<Object> Runtime::GetElementOrCharAt(Isolate* isolate, | 27 MaybeHandle<Object> Runtime::GetElementOrCharAt(Isolate* isolate, |
30 Handle<Object> object, | 28 Handle<Object> object, |
31 uint32_t index) { | 29 uint32_t index) { |
32 // Handle [] indexing on Strings | 30 // Handle [] indexing on Strings |
33 if (object->IsString()) { | 31 if (object->IsString() && |
| 32 index < static_cast<uint32_t>(String::cast(*object)->length())) { |
34 Handle<Object> result = GetCharAt(Handle<String>::cast(object), index); | 33 Handle<Object> result = GetCharAt(Handle<String>::cast(object), index); |
35 if (!result->IsUndefined()) return result; | 34 if (!result->IsUndefined()) return result; |
36 } | 35 } |
37 | 36 |
38 return Object::GetElement(isolate, object, index); | 37 return Object::GetElement(isolate, object, index); |
39 } | 38 } |
40 | 39 |
41 | 40 |
42 MaybeHandle<Name> Runtime::ToName(Isolate* isolate, Handle<Object> key) { | 41 MaybeHandle<Name> Runtime::ToName(Isolate* isolate, Handle<Object> key) { |
43 if (key->IsName()) { | 42 if (key->IsName()) { |
(...skipping 1496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1540 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); | 1539 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); |
1541 | 1540 |
1542 RETURN_FAILURE_ON_EXCEPTION( | 1541 RETURN_FAILURE_ON_EXCEPTION( |
1543 isolate, | 1542 isolate, |
1544 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), | 1543 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), |
1545 setter, attrs)); | 1544 setter, attrs)); |
1546 return isolate->heap()->undefined_value(); | 1545 return isolate->heap()->undefined_value(); |
1547 } | 1546 } |
1548 } // namespace internal | 1547 } // namespace internal |
1549 } // namespace v8 | 1548 } // namespace v8 |
OLD | NEW |