2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef CommonSlowPaths_h
27 #define CommonSlowPaths_h
29 #include "CodeBlock.h"
30 #include "CodeSpecializationKind.h"
31 #include "ExceptionHelpers.h"
33 #include "NameInstance.h"
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).
44 namespace CommonSlowPaths
{
46 ALWAYS_INLINE ExecState
* arityCheckFor(ExecState
* exec
, JSStack
* stack
, CodeSpecializationKind kind
)
48 JSFunction
* callee
= jsCast
<JSFunction
*>(exec
->callee());
49 ASSERT(!callee
->isHostFunction());
50 CodeBlock
* newCodeBlock
= &callee
->jsExecutable()->generatedBytecodeFor(kind
);
51 int argumentCountIncludingThis
= exec
->argumentCountIncludingThis();
53 // This ensures enough space for the worst case scenario of zero arguments passed by the caller.
54 if (!stack
->grow(exec
->registers() + newCodeBlock
->numParameters() + newCodeBlock
->m_numCalleeRegisters
))
57 ASSERT(argumentCountIncludingThis
< newCodeBlock
->numParameters());
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
;
65 int end
= -ExecState::offsetFor(argumentCountIncludingThis
);
66 for (i
= -1; i
>= end
; --i
)
70 for ( ; i
>= end
; --i
)
71 dst
[i
] = jsUndefined();
73 ExecState
* newExec
= ExecState::create(dst
);
74 ASSERT((void*)newExec
<= stack
->end());
78 inline bool opIn(ExecState
* exec
, JSValue propName
, JSValue baseVal
)
80 if (!baseVal
.isObject()) {
81 exec
->vm().exception
= createInvalidParamError(exec
, "in", baseVal
);
85 JSObject
* baseObj
= asObject(baseVal
);
88 if (propName
.getUInt32(i
))
89 return baseObj
->hasProperty(exec
, i
);
92 return baseObj
->hasProperty(exec
, jsCast
<NameInstance
*>(propName
.asCell())->privateName());
94 Identifier
property(exec
, propName
.toString(exec
)->value(exec
));
95 if (exec
->vm().exception
)
97 return baseObj
->hasProperty(exec
, property
);
100 } } // namespace JSC::CommonSlowPaths
102 #endif // CommonSlowPaths_h