* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/builtins/builtins_async_generator.h"
#include "ecmascript/js_async_generator_object.h"
namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsAsyncGenerator::AsyncGeneratorFunctionConstructor(EcmaRuntimeCallInfo *argv)
{
BUILTINS_API_TRACE(argv->GetThread(), AsyncGenerator, Constructor);
THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "Not support eval. Forbidden using new AsyncGeneratorFunction().",
JSTaggedValue::Exception());
}
JSTaggedValue BuiltinsAsyncGenerator::AsyncGeneratorPrototypeNext(EcmaRuntimeCallInfo *argv)
{
JSThread *thread = argv->GetThread();
BUILTINS_API_TRACE(thread, AsyncGenerator, PrototypeNext);
[[maybe_unused]] EcmaHandleScope handleScope(thread);
JSHandle<JSTaggedValue> msg = GetThis(argv);
JSHandle<JSTaggedValue> value = GetCallArg(argv, 0);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<CompletionRecord> completionRecord =
factory->NewCompletionRecord(CompletionRecordType::NORMAL, value);
return JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, msg, completionRecord);
}
JSTaggedValue BuiltinsAsyncGenerator::AsyncGeneratorPrototypeReturn(EcmaRuntimeCallInfo *argv)
{
JSThread *thread = argv->GetThread();
BUILTINS_API_TRACE(thread, AsyncGenerator, PrototypeReturn);
[[maybe_unused]] EcmaHandleScope handleScope(thread);
JSHandle<JSTaggedValue> msg = GetThis(argv);
JSHandle<JSTaggedValue> value = GetCallArg(argv, 0);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<CompletionRecord> completionRecord =
factory->NewCompletionRecord(CompletionRecordType::RETURN, value);
return JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, msg, completionRecord);
}
JSTaggedValue BuiltinsAsyncGenerator::AsyncGeneratorPrototypeThrow(EcmaRuntimeCallInfo *argv)
{
JSThread *thread = argv->GetThread();
BUILTINS_API_TRACE(thread, AsyncGenerator, PrototypeThrow);
[[maybe_unused]] EcmaHandleScope handleScope(thread);
JSHandle<JSTaggedValue> msg = GetThis(argv);
JSHandle<JSTaggedValue> exception = GetCallArg(argv, 0);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<CompletionRecord> completionRecord =
factory->NewCompletionRecord(CompletionRecordType::THROW, exception);
return JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, msg, completionRecord);
}
}