Skip to content

Commit a192ca4

Browse files
Huxprofacebook-github-bot
authored andcommitted
add ES comments for StringIterator
Summary: This diff adds some missing ECMA-262 section comments for StringIterator related functions to guide code readers. Reviewed By: avp Differential Revision: D22396644 fbshipit-source-id: d6fd9185abc2ca44f4d4cefdd9757f6128314f32
1 parent 2aad290 commit a192ca4

4 files changed

Lines changed: 13 additions & 0 deletions

File tree

include/hermes/VM/PrimitiveBox.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class JSString final : public PrimitiveBox {
158158
};
159159

160160
/// StringIterator object.
161+
/// See ES6 21.1.5.3 for Properties of String Iterator Instances.
161162
class JSStringIterator : public JSObject {
162163
using Super = JSObject;
163164

lib/VM/JSLib/String.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,20 +1216,25 @@ stringPrototypeRepeat(void *, Runtime *runtime, NativeArgs args) {
12161216
return builderRes->getStringPrimitive().getHermesValue();
12171217
}
12181218

1219+
/// ES6.0 21.1.3.27 String.prototype [ @@iterator ]( )
12191220
CallResult<HermesValue>
12201221
stringPrototypeSymbolIterator(void *, Runtime *runtime, NativeArgs args) {
1222+
// 1. Let O be RequireObjectCoercible(this value).
12211223
auto thisValue = args.getThisHandle();
12221224
if (LLVM_UNLIKELY(
12231225
checkObjectCoercible(runtime, thisValue) ==
12241226
ExecutionStatus::EXCEPTION)) {
12251227
return ExecutionStatus::EXCEPTION;
12261228
}
1229+
// 2. Let S be ToString(O).
1230+
// 3. ReturnIfAbrupt(S).
12271231
auto strRes = toString_RJS(runtime, thisValue);
12281232
if (LLVM_UNLIKELY(strRes == ExecutionStatus::EXCEPTION)) {
12291233
return ExecutionStatus::EXCEPTION;
12301234
}
12311235
auto string = runtime->makeHandle(std::move(*strRes));
12321236

1237+
// 4. Return CreateStringIterator(S).
12331238
return JSStringIterator::create(runtime, string);
12341239
}
12351240

lib/VM/JSLib/StringIterator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ void populateStringIteratorPrototype(Runtime *runtime) {
4040
dpf);
4141
}
4242

43+
/// ES6.0 21.1.5.2.1 %StringIteratorPrototype%.next ( ) 1-3
4344
CallResult<HermesValue>
4445
stringIteratorPrototypeNext(void *, Runtime *runtime, NativeArgs args) {
46+
// 1. Let O be the this value.
47+
// 2. If Type(O) is not Object, throw a TypeError exception.
48+
// 3. If O does not have all of the internal slots of a String Iterator
49+
// Instance (21.1.5.3), throw a TypeError exception.
4550
auto O = args.dyncastThis<JSStringIterator>();
4651
if (LLVM_UNLIKELY(!O)) {
4752
return runtime->raiseTypeError(

lib/VM/PrimitiveBox.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ void StringIteratorDeserialize(Deserializer &d, CellKind kind) {
236236
}
237237
#endif
238238

239+
/// ES6.0 21.1.5.1 CreateStringIterator Abstract Operation
239240
CallResult<HermesValue> JSStringIterator::create(
240241
Runtime *runtime,
241242
Handle<StringPrimitive> string) {
@@ -251,6 +252,7 @@ CallResult<HermesValue> JSStringIterator::create(
251252
*string));
252253
}
253254

255+
/// ES6.0 21.1.5.2.1 %StringIteratorPrototype%.next ( ) 4-14
254256
CallResult<HermesValue> JSStringIterator::nextElement(
255257
Handle<JSStringIterator> self,
256258
Runtime *runtime) {

0 commit comments

Comments
 (0)