IntlSegmentIteratorPrototype.cpp
1 /* 2 * Copyright (C) 2020 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include "config.h" 27 #include "IntlSegmentIteratorPrototype.h" 28 29 #include "IntlSegmentIterator.h" 30 #include "JSCInlines.h" 31 32 namespace JSC { 33 34 static JSC_DECLARE_HOST_FUNCTION(IntlSegmentIteratorPrototypeFuncNext); 35 36 } 37 38 #include "IntlSegmentIteratorPrototype.lut.h" 39 40 namespace JSC { 41 42 const ClassInfo IntlSegmentIteratorPrototype::s_info = { "Segment String Iterator", &Base::s_info, &segmentIteratorPrototypeTable, nullptr, CREATE_METHOD_TABLE(IntlSegmentIteratorPrototype) }; 43 44 /* Source for IntlSegmentIteratorPrototype.lut.h 45 @begin segmentIteratorPrototypeTable 46 next IntlSegmentIteratorPrototypeFuncNext DontEnum|Function 0 47 @end 48 */ 49 50 IntlSegmentIteratorPrototype* IntlSegmentIteratorPrototype::create(VM& vm, Structure* structure) 51 { 52 auto* object = new (NotNull, allocateCell<IntlSegmentIteratorPrototype>(vm.heap)) IntlSegmentIteratorPrototype(vm, structure); 53 object->finishCreation(vm); 54 return object; 55 } 56 57 Structure* IntlSegmentIteratorPrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) 58 { 59 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info()); 60 } 61 62 IntlSegmentIteratorPrototype::IntlSegmentIteratorPrototype(VM& vm, Structure* structure) 63 : Base(vm, structure) 64 { 65 } 66 67 void IntlSegmentIteratorPrototype::finishCreation(VM& vm) 68 { 69 Base::finishCreation(vm); 70 ASSERT(inherits(vm, info())); 71 JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); 72 } 73 74 // https://tc39.es/proposal-intl-segmenter/#sec-%segmentiteratorprototype%.next 75 JSC_DEFINE_HOST_FUNCTION(IntlSegmentIteratorPrototypeFuncNext, (JSGlobalObject* globalObject, CallFrame* callFrame)) 76 { 77 VM& vm = globalObject->vm(); 78 auto scope = DECLARE_THROW_SCOPE(vm); 79 80 auto* segmentIterator = jsDynamicCast<IntlSegmentIterator*>(vm, callFrame->thisValue()); 81 if (!segmentIterator) 82 return throwVMTypeError(globalObject, scope, "Intl.SegmentIterator.prototype.next called on value that's not an object initialized as a SegmentIterator"_s); 83 84 RELEASE_AND_RETURN(scope, JSValue::encode(segmentIterator->next(globalObject))); 85 } 86 87 } // namespace JSC