blob: 41805782224ff7d1ee46f4e44f005325e353bfe1 [file] [log] [blame]
weinig@apple.com65606f22008-07-12 00:29:24 +00001/*
mark.lam@apple.com60c090d2019-03-07 10:16:58 +00002 * Copyright (C) 2008-2019 Apple Inc. All Rights Reserved.
weinig@apple.com65606f22008-07-12 00:29:24 +00003 *
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. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "ConstructData.h"
28
ggaren@apple.comfea29f12010-05-29 06:33:05 +000029#include "Interpreter.h"
ggaren@apple.comfea29f12010-05-29 06:33:05 +000030#include "JSGlobalObject.h"
ross.kirsling@sony.com0ebe33c2020-05-15 19:39:36 +000031#include "JSObjectInlines.h"
joepeck@webkit.org02fdb7b2015-12-17 23:37:48 +000032#include "ScriptProfilingScope.h"
weinig@apple.com65606f22008-07-12 00:29:24 +000033
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000034namespace JSC {
weinig@apple.com65606f22008-07-12 00:29:24 +000035
cdumez@apple.com1392b8b2022-03-24 01:40:35 +000036JSObject* construct(JSGlobalObject* globalObject, JSValue constructorObject, const ArgList& args, ASCIILiteral errorMessage)
keith_miller@apple.com1d63b102016-01-30 02:45:25 +000037{
keith_miller@apple.coma1c17ed2020-01-17 04:09:32 +000038 return construct(globalObject, constructorObject, constructorObject, args, errorMessage);
39}
40
cdumez@apple.com1392b8b2022-03-24 01:40:35 +000041JSObject* construct(JSGlobalObject* globalObject, JSValue constructorObject, JSValue newTarget, const ArgList& args, ASCIILiteral errorMessage)
keith_miller@apple.coma1c17ed2020-01-17 04:09:32 +000042{
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000043 VM& vm = globalObject->vm();
mark.lam@apple.com284f4562016-08-30 20:54:54 +000044 auto scope = DECLARE_THROW_SCOPE(vm);
45
ysuzuki@apple.com984775d2022-04-16 00:00:35 +000046 auto constructData = JSC::getConstructData(constructorObject);
ross.kirsling@sony.com924e7502020-04-27 09:09:32 +000047 if (UNLIKELY(constructData.type == CallData::Type::None)) {
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000048 throwTypeError(globalObject, scope, errorMessage);
mark.lam@apple.com60c090d2019-03-07 10:16:58 +000049 return nullptr;
50 }
keith_miller@apple.com1d63b102016-01-30 02:45:25 +000051
ross.kirsling@sony.com924e7502020-04-27 09:09:32 +000052 RELEASE_AND_RETURN(scope, construct(globalObject, constructorObject, constructData, args, newTarget));
keith_miller@apple.com1d63b102016-01-30 02:45:25 +000053}
54
ross.kirsling@sony.com924e7502020-04-27 09:09:32 +000055JSObject* construct(JSGlobalObject* globalObject, JSValue constructorObject, const CallData& constructData, const ArgList& args, JSValue newTarget)
weinig@apple.com65606f22008-07-12 00:29:24 +000056{
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000057 VM& vm = globalObject->vm();
ross.kirsling@sony.com924e7502020-04-27 09:09:32 +000058 ASSERT(constructData.type == CallData::Type::JS || constructData.type == CallData::Type::Native);
59 return vm.interpreter->executeConstruct(globalObject, asObject(constructorObject), constructData, args, newTarget);
weinig@apple.com65606f22008-07-12 00:29:24 +000060}
61
ross.kirsling@sony.com924e7502020-04-27 09:09:32 +000062JSObject* profiledConstruct(JSGlobalObject* globalObject, ProfilingReason reason, JSValue constructorObject, const CallData& constructData, const ArgList& args, JSValue newTarget)
joepeck@webkit.org02fdb7b2015-12-17 23:37:48 +000063{
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000064 VM& vm = globalObject->vm();
65 ScriptProfilingScope profilingScope(vm.deprecatedVMEntryGlobalObject(globalObject), reason);
ross.kirsling@sony.com924e7502020-04-27 09:09:32 +000066 return construct(globalObject, constructorObject, constructData, args, newTarget);
joepeck@webkit.org02fdb7b2015-12-17 23:37:48 +000067}
68
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000069} // namespace JSC