weinig@apple.com | 65606f2 | 2008-07-12 00:29:24 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | 60c090d | 2019-03-07 10:16:58 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008-2019 Apple Inc. All Rights Reserved. |
weinig@apple.com | 65606f2 | 2008-07-12 00:29:24 +0000 | [diff] [blame] | 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. ``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.com | fea29f1 | 2010-05-29 06:33:05 +0000 | [diff] [blame] | 29 | #include "Interpreter.h" |
ggaren@apple.com | fea29f1 | 2010-05-29 06:33:05 +0000 | [diff] [blame] | 30 | #include "JSGlobalObject.h" |
ross.kirsling@sony.com | 0ebe33c | 2020-05-15 19:39:36 +0000 | [diff] [blame] | 31 | #include "JSObjectInlines.h" |
joepeck@webkit.org | 02fdb7b | 2015-12-17 23:37:48 +0000 | [diff] [blame] | 32 | #include "ScriptProfilingScope.h" |
weinig@apple.com | 65606f2 | 2008-07-12 00:29:24 +0000 | [diff] [blame] | 33 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 34 | namespace JSC { |
weinig@apple.com | 65606f2 | 2008-07-12 00:29:24 +0000 | [diff] [blame] | 35 | |
cdumez@apple.com | 1392b8b | 2022-03-24 01:40:35 +0000 | [diff] [blame] | 36 | JSObject* construct(JSGlobalObject* globalObject, JSValue constructorObject, const ArgList& args, ASCIILiteral errorMessage) |
keith_miller@apple.com | 1d63b10 | 2016-01-30 02:45:25 +0000 | [diff] [blame] | 37 | { |
keith_miller@apple.com | a1c17ed | 2020-01-17 04:09:32 +0000 | [diff] [blame] | 38 | return construct(globalObject, constructorObject, constructorObject, args, errorMessage); |
| 39 | } |
| 40 | |
cdumez@apple.com | 1392b8b | 2022-03-24 01:40:35 +0000 | [diff] [blame] | 41 | JSObject* construct(JSGlobalObject* globalObject, JSValue constructorObject, JSValue newTarget, const ArgList& args, ASCIILiteral errorMessage) |
keith_miller@apple.com | a1c17ed | 2020-01-17 04:09:32 +0000 | [diff] [blame] | 42 | { |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 43 | VM& vm = globalObject->vm(); |
mark.lam@apple.com | 284f456 | 2016-08-30 20:54:54 +0000 | [diff] [blame] | 44 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 45 | |
ysuzuki@apple.com | 984775d | 2022-04-16 00:00:35 +0000 | [diff] [blame] | 46 | auto constructData = JSC::getConstructData(constructorObject); |
ross.kirsling@sony.com | 924e750 | 2020-04-27 09:09:32 +0000 | [diff] [blame] | 47 | if (UNLIKELY(constructData.type == CallData::Type::None)) { |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 48 | throwTypeError(globalObject, scope, errorMessage); |
mark.lam@apple.com | 60c090d | 2019-03-07 10:16:58 +0000 | [diff] [blame] | 49 | return nullptr; |
| 50 | } |
keith_miller@apple.com | 1d63b10 | 2016-01-30 02:45:25 +0000 | [diff] [blame] | 51 | |
ross.kirsling@sony.com | 924e750 | 2020-04-27 09:09:32 +0000 | [diff] [blame] | 52 | RELEASE_AND_RETURN(scope, construct(globalObject, constructorObject, constructData, args, newTarget)); |
keith_miller@apple.com | 1d63b10 | 2016-01-30 02:45:25 +0000 | [diff] [blame] | 53 | } |
| 54 | |
ross.kirsling@sony.com | 924e750 | 2020-04-27 09:09:32 +0000 | [diff] [blame] | 55 | JSObject* construct(JSGlobalObject* globalObject, JSValue constructorObject, const CallData& constructData, const ArgList& args, JSValue newTarget) |
weinig@apple.com | 65606f2 | 2008-07-12 00:29:24 +0000 | [diff] [blame] | 56 | { |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 57 | VM& vm = globalObject->vm(); |
ross.kirsling@sony.com | 924e750 | 2020-04-27 09:09:32 +0000 | [diff] [blame] | 58 | ASSERT(constructData.type == CallData::Type::JS || constructData.type == CallData::Type::Native); |
| 59 | return vm.interpreter->executeConstruct(globalObject, asObject(constructorObject), constructData, args, newTarget); |
weinig@apple.com | 65606f2 | 2008-07-12 00:29:24 +0000 | [diff] [blame] | 60 | } |
| 61 | |
ross.kirsling@sony.com | 924e750 | 2020-04-27 09:09:32 +0000 | [diff] [blame] | 62 | JSObject* profiledConstruct(JSGlobalObject* globalObject, ProfilingReason reason, JSValue constructorObject, const CallData& constructData, const ArgList& args, JSValue newTarget) |
joepeck@webkit.org | 02fdb7b | 2015-12-17 23:37:48 +0000 | [diff] [blame] | 63 | { |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 64 | VM& vm = globalObject->vm(); |
| 65 | ScriptProfilingScope profilingScope(vm.deprecatedVMEntryGlobalObject(globalObject), reason); |
ross.kirsling@sony.com | 924e750 | 2020-04-27 09:09:32 +0000 | [diff] [blame] | 66 | return construct(globalObject, constructorObject, constructData, args, newTarget); |
joepeck@webkit.org | 02fdb7b | 2015-12-17 23:37:48 +0000 | [diff] [blame] | 67 | } |
| 68 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 69 | } // namespace JSC |