1 | /* |
2 | * Copyright (C) 2015 Yusuke Suzuki <[email protected]>. |
3 | * Copyright (C) 2016-2017 Apple Inc. All rights reserved. |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | */ |
26 | |
27 | #include "config.h" |
28 | #include "BytecodeIntrinsicRegistry.h" |
29 | |
30 | #include "ArrayIteratorPrototype.h" |
31 | #include "BuiltinNames.h" |
32 | #include "BytecodeGenerator.h" |
33 | #include "IterationKind.h" |
34 | #include "JSAsyncGeneratorFunction.h" |
35 | #include "JSCInlines.h" |
36 | #include "JSGeneratorFunction.h" |
37 | #include "JSGlobalObject.h" |
38 | #include "JSModuleLoader.h" |
39 | #include "JSPromise.h" |
40 | #include "Nodes.h" |
41 | #include "StrongInlines.h" |
42 | |
43 | namespace JSC { |
44 | |
45 | #define INITIALIZE_BYTECODE_INTRINSIC_NAMES_TO_SET(name) m_bytecodeIntrinsicMap.add(vm.propertyNames->builtinNames().name##PrivateName().impl(), &BytecodeIntrinsicNode::emit_intrinsic_##name); |
46 | |
47 | BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry(VM& vm) |
48 | : m_vm(vm) |
49 | , m_bytecodeIntrinsicMap() |
50 | { |
51 | JSC_COMMON_BYTECODE_INTRINSIC_FUNCTIONS_EACH_NAME(INITIALIZE_BYTECODE_INTRINSIC_NAMES_TO_SET) |
52 | JSC_COMMON_BYTECODE_INTRINSIC_CONSTANTS_EACH_NAME(INITIALIZE_BYTECODE_INTRINSIC_NAMES_TO_SET) |
53 | |
54 | m_undefined.set(m_vm, jsUndefined()); |
55 | m_Infinity.set(m_vm, jsDoubleNumber(std::numeric_limits<double>::infinity())); |
56 | m_iterationKindKey.set(m_vm, jsNumber(IterateKey)); |
57 | m_iterationKindValue.set(m_vm, jsNumber(IterateValue)); |
58 | m_iterationKindKeyValue.set(m_vm, jsNumber(IterateKeyValue)); |
59 | m_MAX_ARRAY_INDEX.set(m_vm, jsNumber(MAX_ARRAY_INDEX)); |
60 | m_MAX_STRING_LENGTH.set(m_vm, jsNumber(JSString::MaxLength)); |
61 | m_MAX_SAFE_INTEGER.set(m_vm, jsDoubleNumber(maxSafeInteger())); |
62 | m_ModuleFetch.set(m_vm, jsNumber(static_cast<unsigned>(JSModuleLoader::Status::Fetch))); |
63 | m_ModuleInstantiate.set(m_vm, jsNumber(static_cast<unsigned>(JSModuleLoader::Status::Instantiate))); |
64 | m_ModuleSatisfy.set(m_vm, jsNumber(static_cast<unsigned>(JSModuleLoader::Status::Satisfy))); |
65 | m_ModuleLink.set(m_vm, jsNumber(static_cast<unsigned>(JSModuleLoader::Status::Link))); |
66 | m_ModuleReady.set(m_vm, jsNumber(static_cast<unsigned>(JSModuleLoader::Status::Ready))); |
67 | m_promiseRejectionReject.set(m_vm, jsNumber(static_cast<unsigned>(JSPromiseRejectionOperation::Reject))); |
68 | m_promiseRejectionHandle.set(m_vm, jsNumber(static_cast<unsigned>(JSPromiseRejectionOperation::Handle))); |
69 | m_promiseStatePending.set(m_vm, jsNumber(static_cast<unsigned>(JSPromise::Status::Pending))); |
70 | m_promiseStateFulfilled.set(m_vm, jsNumber(static_cast<unsigned>(JSPromise::Status::Fulfilled))); |
71 | m_promiseStateRejected.set(m_vm, jsNumber(static_cast<unsigned>(JSPromise::Status::Rejected))); |
72 | m_GeneratorResumeModeNormal.set(m_vm, jsNumber(static_cast<int32_t>(JSGeneratorFunction::GeneratorResumeMode::NormalMode))); |
73 | m_GeneratorResumeModeThrow.set(m_vm, jsNumber(static_cast<int32_t>(JSGeneratorFunction::GeneratorResumeMode::ThrowMode))); |
74 | m_GeneratorResumeModeReturn.set(m_vm, jsNumber(static_cast<int32_t>(JSGeneratorFunction::GeneratorResumeMode::ReturnMode))); |
75 | m_GeneratorStateCompleted.set(m_vm, jsNumber(static_cast<int32_t>(JSGeneratorFunction::GeneratorState::Completed))); |
76 | m_GeneratorStateExecuting.set(m_vm, jsNumber(static_cast<int32_t>(JSGeneratorFunction::GeneratorState::Executing))); |
77 | m_AsyncGeneratorStateCompleted.set(m_vm, jsNumber(static_cast<int32_t>(JSAsyncGeneratorFunction::AsyncGeneratorState::Completed))); |
78 | m_AsyncGeneratorStateExecuting.set(m_vm, jsNumber(static_cast<int32_t>(JSAsyncGeneratorFunction::AsyncGeneratorState::Executing))); |
79 | m_AsyncGeneratorStateSuspendedStart.set(m_vm, jsNumber(static_cast<int32_t>(JSAsyncGeneratorFunction::AsyncGeneratorState::SuspendedStart))); |
80 | m_AsyncGeneratorStateSuspendedYield.set(m_vm, jsNumber(static_cast<int32_t>(JSAsyncGeneratorFunction::AsyncGeneratorState::SuspendedYield))); |
81 | m_AsyncGeneratorStateAwaitingReturn.set(m_vm, jsNumber(static_cast<int32_t>(JSAsyncGeneratorFunction::AsyncGeneratorState::AwaitingReturn))); |
82 | m_AsyncGeneratorSuspendReasonYield.set(m_vm, jsNumber(static_cast<int32_t>(JSAsyncGeneratorFunction::AsyncGeneratorSuspendReason::Yield))); |
83 | m_AsyncGeneratorSuspendReasonAwait.set(m_vm, jsNumber(static_cast<int32_t>(JSAsyncGeneratorFunction::AsyncGeneratorSuspendReason::Await))); |
84 | m_AsyncGeneratorSuspendReasonNone.set(m_vm, jsNumber(static_cast<int32_t>(JSAsyncGeneratorFunction::AsyncGeneratorSuspendReason::None))); |
85 | } |
86 | |
87 | BytecodeIntrinsicNode::EmitterType BytecodeIntrinsicRegistry::lookup(const Identifier& ident) const |
88 | { |
89 | if (!ident.isPrivateName()) |
90 | return nullptr; |
91 | auto iterator = m_bytecodeIntrinsicMap.find(ident.impl()); |
92 | if (iterator == m_bytecodeIntrinsicMap.end()) |
93 | return nullptr; |
94 | return iterator->value; |
95 | } |
96 | |
97 | #define JSC_DECLARE_BYTECODE_INTRINSIC_CONSTANT_GENERATORS(name) \ |
98 | JSValue BytecodeIntrinsicRegistry::name##Value(BytecodeGenerator&) \ |
99 | { \ |
100 | return m_##name.get(); \ |
101 | } |
102 | JSC_COMMON_BYTECODE_INTRINSIC_CONSTANTS_SIMPLE_EACH_NAME(JSC_DECLARE_BYTECODE_INTRINSIC_CONSTANT_GENERATORS) |
103 | #undef JSC_DECLARE_BYTECODE_INTRINSIC_CONSTANT_GENERATORS |
104 | |
105 | JSValue BytecodeIntrinsicRegistry::sentinelMapBucketValue(BytecodeGenerator& generator) |
106 | { |
107 | return generator.vm()->sentinelMapBucket(); |
108 | } |
109 | |
110 | JSValue BytecodeIntrinsicRegistry::sentinelSetBucketValue(BytecodeGenerator& generator) |
111 | { |
112 | return generator.vm()->sentinelSetBucket(); |
113 | } |
114 | |
115 | } // namespace JSC |
116 | |
117 | |