blob: b30c2ae0b47e266037bcf945409f63b67ec5fb05 [file] [log] [blame]
yaar@chromium.org37eb4772010-05-20 21:56:45 +00001/*
2 * Copyright (C) 2010 Google 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"
utatane.tea@gmail.com11098d62018-08-06 04:37:10 +000027#include "JSExecState.h"
weinig@apple.com440ba0d2015-12-03 19:06:45 +000028
rniwa@webkit.org212d9bf2019-11-21 01:47:56 +000029#include "EventLoop.h"
joepeck@webkit.orga6dfe9c2017-04-28 03:33:57 +000030#include "RejectedPromiseTracker.h"
31#include "ScriptExecutionContext.h"
utatane.tea@gmail.com11098d62018-08-06 04:37:10 +000032#include "WorkerGlobalScope.h"
yaar@chromium.org37eb4772010-05-20 21:56:45 +000033
34namespace WebCore {
35
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000036void JSExecState::didLeaveScriptContext(JSC::JSGlobalObject* lexicalGlobalObject)
adamk@chromium.org82abc772012-02-08 00:40:31 +000037{
darin@apple.com356814b2021-12-21 21:56:30 +000038 auto context = executionContext(lexicalGlobalObject);
yusukesuzuki@slowstart.org50472952018-08-14 17:45:09 +000039 if (!context)
40 return;
rniwa@webkit.org212d9bf2019-11-21 01:47:56 +000041 context->eventLoop().performMicrotaskCheckpoint();
gnavamarino@apple.comf4ce59c2022-04-12 18:08:56 +000042 if (auto rejectedPromiseTracker = context->ensureRejectedPromiseTracker())
43 rejectedPromiseTracker->processQueueSoon();
charles.wei@torchmobile.com.cnf3b125d2012-06-08 23:41:36 +000044}
45
ross.kirsling@sony.com924e7502020-04-27 09:09:32 +000046JSC::JSValue functionCallHandlerFromAnyThread(JSC::JSGlobalObject* lexicalGlobalObject, JSC::JSValue functionObject, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args, NakedPtr<JSC::Exception>& returnedException)
joepeck@webkit.orga3198442013-12-11 22:40:23 +000047{
ross.kirsling@sony.com924e7502020-04-27 09:09:32 +000048 return JSExecState::call(lexicalGlobalObject, functionObject, callData, thisValue, args, returnedException);
joepeck@webkit.org69a4eaf2014-01-09 19:00:48 +000049}
50
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000051JSC::JSValue evaluateHandlerFromAnyThread(JSC::JSGlobalObject* lexicalGlobalObject, const JSC::SourceCode& source, JSC::JSValue thisValue, NakedPtr<JSC::Exception>& returnedException)
joepeck@webkit.org69a4eaf2014-01-09 19:00:48 +000052{
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000053 return JSExecState::evaluate(lexicalGlobalObject, source, thisValue, returnedException);
joepeck@webkit.orga3198442013-12-11 22:40:23 +000054}
55
darin@apple.com356814b2021-12-21 21:56:30 +000056ScriptExecutionContext* executionContext(JSC::JSGlobalObject* globalObject)
57{
ysuzuki@apple.com984775d2022-04-16 00:00:35 +000058 if (!globalObject || !globalObject->inherits<JSDOMGlobalObject>())
darin@apple.com356814b2021-12-21 21:56:30 +000059 return nullptr;
aperez@igalia.come3adaf52021-12-30 22:33:31 +000060 return JSC::jsCast<JSDOMGlobalObject*>(globalObject)->scriptExecutionContext();
darin@apple.com356814b2021-12-21 21:56:30 +000061}
62
yaar@chromium.org37eb4772010-05-20 21:56:45 +000063} // namespace WebCore