blob: feb7cb82f22eda88f452c9e3873b6ca95ad190f0 [file] [log] [blame]
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +00001/*
2 * Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>.
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 "GeneratorFunctionConstructor.h"
28
29#include "FunctionConstructor.h"
30#include "GeneratorFunctionPrototype.h"
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000031
32namespace JSC {
33
34STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(GeneratorFunctionConstructor);
35
utatane.tea@gmail.coma5544f12017-05-19 09:23:20 +000036const ClassInfo GeneratorFunctionConstructor::s_info = { "GeneratorFunction", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(GeneratorFunctionConstructor) };
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000037
ysuzuki@apple.com622e8692019-10-07 23:13:45 +000038static EncodedJSValue JSC_HOST_CALL callGeneratorFunctionConstructor(JSGlobalObject* globalObject, CallFrame* callFrame)
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000039{
ysuzuki@apple.com622e8692019-10-07 23:13:45 +000040 ArgList args(callFrame);
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000041 return JSValue::encode(constructFunction(globalObject, callFrame, args, FunctionConstructionMode::Generator));
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000042}
43
ysuzuki@apple.com622e8692019-10-07 23:13:45 +000044static EncodedJSValue JSC_HOST_CALL constructGeneratorFunctionConstructor(JSGlobalObject* globalObject, CallFrame* callFrame)
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000045{
ysuzuki@apple.com622e8692019-10-07 23:13:45 +000046 ArgList args(callFrame);
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000047 return JSValue::encode(constructFunction(globalObject, callFrame, args, FunctionConstructionMode::Generator, callFrame->newTarget()));
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000048}
49
utatane.tea@gmail.com7ab015d2017-11-06 14:40:08 +000050GeneratorFunctionConstructor::GeneratorFunctionConstructor(VM& vm, Structure* structure)
51 : InternalFunction(vm, structure, callGeneratorFunctionConstructor, constructGeneratorFunctionConstructor)
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000052{
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000053}
54
utatane.tea@gmail.com7ab015d2017-11-06 14:40:08 +000055void GeneratorFunctionConstructor::finishCreation(VM& vm, GeneratorFunctionPrototype* generatorFunctionPrototype)
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000056{
ross.kirsling@sony.com0e4a9cf2019-11-16 03:44:26 +000057 Base::finishCreation(vm, "GeneratorFunction"_s, NameAdditionMode::WithoutStructureTransition);
utatane.tea@gmail.com7ab015d2017-11-06 14:40:08 +000058 putDirectWithoutTransition(vm, vm.propertyNames->prototype, generatorFunctionPrototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
59 putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum);
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000060}
61
62} // namespace JSC