• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ecmascript/async_generator_helper.h"
17 #include "ecmascript/builtins/builtins_promise.h"
18 #include "ecmascript/interpreter/interpreter-inl.h"
19 #include "ecmascript/js_iterator.h"
20 #include "ecmascript/js_promise.h"
21 #include "ecmascript/tagged_queue.h"
22 
23 namespace panda::ecmascript {
24 using BuiltinsPromise = builtins::BuiltinsPromise;
Next(JSThread * thread,const JSHandle<GeneratorContext> & genContext,JSTaggedValue value)25 JSTaggedValue AsyncGeneratorHelper::Next(JSThread *thread, const JSHandle<GeneratorContext> &genContext,
26                                          JSTaggedValue value)
27 {
28     JSHandle<JSAsyncGeneratorObject> genObject(thread, genContext->GetGeneratorObject());
29     genObject->SetResumeResult(thread, value);
30     genObject->SetResumeMode(AsyncGeneratorResumeMode::NEXT);
31 
32     EcmaInterpreter::GeneratorReEnterInterpreter(thread, genContext);
33     return JSTaggedValue::Undefined();
34 }
35 
Throw(JSThread * thread,const JSHandle<GeneratorContext> & genContext,const JSHandle<CompletionRecord> completionRecord)36 JSTaggedValue AsyncGeneratorHelper::Throw(JSThread *thread, const JSHandle<GeneratorContext> &genContext,
37                                           const JSHandle<CompletionRecord> completionRecord)
38 {
39     JSHandle<JSAsyncGeneratorObject> genObject(thread, genContext->GetGeneratorObject());
40     genObject->SetResumeResult(thread, completionRecord->GetValue());
41     genObject->SetResumeMode(AsyncGeneratorResumeMode::THROW);
42 
43     EcmaInterpreter::GeneratorReEnterInterpreter(thread, genContext);
44     return JSTaggedValue::Undefined();
45 }
46 
Return(JSThread * thread,const JSHandle<GeneratorContext> & genContext,const JSHandle<CompletionRecord> completionRecord)47 JSTaggedValue AsyncGeneratorHelper::Return(JSThread *thread, const JSHandle<GeneratorContext> &genContext,
48                                            const JSHandle<CompletionRecord> completionRecord)
49 {
50     JSHandle<JSAsyncGeneratorObject> genObject(thread, genContext->GetGeneratorObject());
51     genObject->SetResumeResult(thread, completionRecord->GetValue());
52     genObject->SetResumeMode(AsyncGeneratorResumeMode::RETURN);
53 
54     EcmaInterpreter::GeneratorReEnterInterpreter(thread, genContext);
55     return JSTaggedValue::Undefined();
56 }
57 }  // namespace panda::ecmascript
58