Port StringPrototypeIterator to Torque
Bug: v8:8996 Change-Id: I7930d98a9ff3b341611b2833b6847615b0ac467d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1593856 Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com> Reviewed-by: Simon Zünd <szuend@chromium.org> Cr-Commit-Position: refs/heads/master@{#61220}
This commit is contained in:
parent
6c0e95f4fc
commit
c862f5914d
2
BUILD.gn
2
BUILD.gn
@ -951,6 +951,7 @@ torque_files = [
|
||||
"src/builtins/regexp-replace.tq",
|
||||
"src/builtins/string-endswith.tq",
|
||||
"src/builtins/string-html.tq",
|
||||
"src/builtins/string-iterator.tq",
|
||||
"src/builtins/string-repeat.tq",
|
||||
"src/builtins/string-startswith.tq",
|
||||
"src/builtins/typed-array.tq",
|
||||
@ -1005,6 +1006,7 @@ torque_namespaces = [
|
||||
"regexp-replace",
|
||||
"string",
|
||||
"string-html",
|
||||
"string-iterator",
|
||||
"string-repeat",
|
||||
"test",
|
||||
"typed-array",
|
||||
|
@ -443,6 +443,8 @@ const REFLECT_APPLY_INDEX: constexpr NativeContextSlot
|
||||
generates 'Context::REFLECT_APPLY_INDEX';
|
||||
const REGEXP_LAST_MATCH_INFO_INDEX: constexpr NativeContextSlot
|
||||
generates 'Context::REGEXP_LAST_MATCH_INFO_INDEX';
|
||||
const INITIAL_STRING_ITERATOR_MAP_INDEX: constexpr NativeContextSlot
|
||||
generates 'Context::INITIAL_STRING_ITERATOR_MAP_INDEX';
|
||||
extern operator '[]' macro LoadContextElement(
|
||||
NativeContext, NativeContextSlot): Object;
|
||||
extern operator '[]=' macro StoreContextElement(
|
||||
@ -2181,6 +2183,10 @@ macro GetProxyRevocableResultMap(implicit context: Context)(): Map {
|
||||
return UnsafeCast<Map>(
|
||||
LoadNativeContext(context)[PROXY_REVOCABLE_RESULT_MAP_INDEX]);
|
||||
}
|
||||
macro GetInitialStringIteratorMap(implicit context: Context)(): Map {
|
||||
return UnsafeCast<Map>(
|
||||
LoadNativeContext(context)[INITIAL_STRING_ITERATOR_MAP_INDEX]);
|
||||
}
|
||||
macro GetReflectApply(implicit context: Context)(): Callable {
|
||||
return UnsafeCast<Callable>(LoadNativeContext(context)[REFLECT_APPLY_INDEX]);
|
||||
}
|
||||
|
@ -1002,8 +1002,6 @@ namespace internal {
|
||||
TFJ(StringPrototypeValueOf, 0, kReceiver) \
|
||||
/* ES6 #sec-string.raw */ \
|
||||
CPP(StringRaw) \
|
||||
/* ES6 #sec-string.prototype-@@iterator */ \
|
||||
TFJ(StringPrototypeIterator, 0, kReceiver) \
|
||||
\
|
||||
/* StringIterator */ \
|
||||
/* ES6 #sec-%stringiteratorprototype%.next */ \
|
||||
|
@ -2223,30 +2223,6 @@ TF_BUILTIN(StringPrototypeValueOf, CodeStubAssembler) {
|
||||
Return(result);
|
||||
}
|
||||
|
||||
TF_BUILTIN(StringPrototypeIterator, CodeStubAssembler) {
|
||||
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
|
||||
TNode<Object> receiver = CAST(Parameter(Descriptor::kReceiver));
|
||||
|
||||
Node* string =
|
||||
ToThisString(context, receiver, "String.prototype[Symbol.iterator]");
|
||||
|
||||
Node* native_context = LoadNativeContext(context);
|
||||
Node* map = LoadContextElement(native_context,
|
||||
Context::INITIAL_STRING_ITERATOR_MAP_INDEX);
|
||||
Node* iterator = Allocate(JSStringIterator::kSize);
|
||||
StoreMapNoWriteBarrier(iterator, map);
|
||||
StoreObjectFieldRoot(iterator, JSValue::kPropertiesOrHashOffset,
|
||||
RootIndex::kEmptyFixedArray);
|
||||
StoreObjectFieldRoot(iterator, JSObject::kElementsOffset,
|
||||
RootIndex::kEmptyFixedArray);
|
||||
StoreObjectFieldNoWriteBarrier(iterator, JSStringIterator::kStringOffset,
|
||||
string);
|
||||
Node* index = SmiConstant(0);
|
||||
StoreObjectFieldNoWriteBarrier(iterator, JSStringIterator::kNextIndexOffset,
|
||||
index);
|
||||
Return(iterator);
|
||||
}
|
||||
|
||||
// Return the |word32| codepoint at {index}. Supports SeqStrings and
|
||||
// ExternalStrings.
|
||||
TNode<Int32T> StringBuiltinsAssembler::LoadSurrogatePairAt(
|
||||
|
26
src/builtins/string-iterator.tq
Normal file
26
src/builtins/string-iterator.tq
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright 2019 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
namespace string_iterator {
|
||||
|
||||
macro NewJSStringIterator(implicit context: Context)(
|
||||
string: String, nextIndex: Smi): JSStringIterator {
|
||||
return new JSStringIterator{
|
||||
map: GetInitialStringIteratorMap(),
|
||||
properties_or_hash: kEmptyFixedArray,
|
||||
elements: kEmptyFixedArray,
|
||||
string: string,
|
||||
next_index: nextIndex
|
||||
};
|
||||
}
|
||||
|
||||
// ES6 #sec-string.prototype-@@iterator
|
||||
transitioning javascript builtin StringPrototypeIterator(
|
||||
implicit context: Context)(receiver: Object): JSStringIterator {
|
||||
const name: String =
|
||||
ToThisString(receiver, 'String.prototype[Symbol.iterator]');
|
||||
const index: Smi = 0;
|
||||
return NewJSStringIterator(name, index);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user