]>
Commit | Line | Data |
---|---|---|
6fe7ccc8 A |
1 | /* |
2 | * Copyright (C) 2011, 2012 Apple 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. ``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 | #ifndef CommonSlowPaths_h | |
27 | #define CommonSlowPaths_h | |
28 | ||
29 | #include "CodeBlock.h" | |
30 | #include "CodeSpecializationKind.h" | |
31 | #include "ExceptionHelpers.h" | |
32 | #include "JSArray.h" | |
93a37866 | 33 | #include "NameInstance.h" |
6fe7ccc8 A |
34 | |
35 | namespace JSC { | |
36 | ||
37 | // The purpose of this namespace is to include slow paths that are shared | |
38 | // between the interpreter and baseline JIT. They are written to be agnostic | |
39 | // with respect to the slow-path calling convention, but they do rely on the | |
40 | // JS code being executed more-or-less directly from bytecode (so the call | |
41 | // frame layout is unmodified, making it potentially awkward to use these | |
42 | // from any optimizing JIT, like the DFG). | |
43 | ||
44 | namespace CommonSlowPaths { | |
45 | ||
93a37866 | 46 | ALWAYS_INLINE ExecState* arityCheckFor(ExecState* exec, JSStack* stack, CodeSpecializationKind kind) |
6fe7ccc8 A |
47 | { |
48 | JSFunction* callee = jsCast<JSFunction*>(exec->callee()); | |
49 | ASSERT(!callee->isHostFunction()); | |
50 | CodeBlock* newCodeBlock = &callee->jsExecutable()->generatedBytecodeFor(kind); | |
51 | int argumentCountIncludingThis = exec->argumentCountIncludingThis(); | |
52 | ||
53 | // This ensures enough space for the worst case scenario of zero arguments passed by the caller. | |
93a37866 | 54 | if (!stack->grow(exec->registers() + newCodeBlock->numParameters() + newCodeBlock->m_numCalleeRegisters)) |
6fe7ccc8 A |
55 | return 0; |
56 | ||
57 | ASSERT(argumentCountIncludingThis < newCodeBlock->numParameters()); | |
58 | ||
59 | // Too few arguments -- copy call frame and arguments, then fill in missing arguments with undefined. | |
60 | size_t delta = newCodeBlock->numParameters() - argumentCountIncludingThis; | |
61 | Register* src = exec->registers(); | |
62 | Register* dst = exec->registers() + delta; | |
63 | ||
64 | int i; | |
65 | int end = -ExecState::offsetFor(argumentCountIncludingThis); | |
66 | for (i = -1; i >= end; --i) | |
67 | dst[i] = src[i]; | |
68 | ||
69 | end -= delta; | |
70 | for ( ; i >= end; --i) | |
71 | dst[i] = jsUndefined(); | |
72 | ||
73 | ExecState* newExec = ExecState::create(dst); | |
93a37866 | 74 | ASSERT((void*)newExec <= stack->end()); |
6fe7ccc8 A |
75 | return newExec; |
76 | } | |
77 | ||
6fe7ccc8 A |
78 | inline bool opIn(ExecState* exec, JSValue propName, JSValue baseVal) |
79 | { | |
80 | if (!baseVal.isObject()) { | |
93a37866 | 81 | exec->vm().exception = createInvalidParamError(exec, "in", baseVal); |
6fe7ccc8 A |
82 | return false; |
83 | } | |
84 | ||
85 | JSObject* baseObj = asObject(baseVal); | |
86 | ||
87 | uint32_t i; | |
88 | if (propName.getUInt32(i)) | |
89 | return baseObj->hasProperty(exec, i); | |
90 | ||
93a37866 A |
91 | if (isName(propName)) |
92 | return baseObj->hasProperty(exec, jsCast<NameInstance*>(propName.asCell())->privateName()); | |
93 | ||
6fe7ccc8 | 94 | Identifier property(exec, propName.toString(exec)->value(exec)); |
93a37866 | 95 | if (exec->vm().exception) |
6fe7ccc8 A |
96 | return false; |
97 | return baseObj->hasProperty(exec, property); | |
98 | } | |
99 | ||
6fe7ccc8 A |
100 | } } // namespace JSC::CommonSlowPaths |
101 | ||
102 | #endif // CommonSlowPaths_h |