source: webkit/trunk/JavaScriptCore/VM/CodeBlock.h@ 34457

Last change on this file since 34457 was 34457, checked in by [email protected], 17 years ago

2008-06-08 Cameron Zwarich <[email protected]>

Reviewed by Darin.

Bug 19346: REGRESSION: Mootools 1.2 Class inheritance broken in post-SquirrelFish merge
<https://bugs.webkit.org/show_bug.cgi?id=19346>

A check for whether a function's caller is eval code accidentally included
the case where the caller's caller is native code. Add a CodeType field to
CodeBlock and use this for the eval caller test instead.

JavaScriptCore:

  • VM/CodeBlock.h: (KJS::CodeBlock::CodeBlock): (KJS::ProgramCodeBlock::ProgramCodeBlock): (KJS::EvalCodeBlock::EvalCodeBlock):
  • VM/Machine.cpp: (KJS::getCallerFunctionOffset):
  • kjs/nodes.cpp: (KJS::FunctionBodyNode::generateCode): (KJS::ProgramNode::generateCode):

LayoutTests:

  • fast/js/function-dot-arguments-and-caller-expected.txt:
  • fast/js/function-dot-arguments-and-caller.html:
File size: 4.4 KB
Line 
1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Cameron Zwarich <[email protected]>
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 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef CodeBlock_h
31#define CodeBlock_h
32
33#include "Instruction.h"
34#include "JSGlobalObject.h"
35#include "nodes.h"
36#include "ustring.h"
37#include <wtf/RefPtr.h>
38#include <wtf/Vector.h>
39
40namespace KJS {
41
42 class ExecState;
43
44 static ALWAYS_INLINE int missingThisObjectMarker() { return std::numeric_limits<int>::max(); }
45
46 struct HandlerInfo {
47 unsigned start;
48 unsigned end;
49 unsigned target;
50 unsigned scopeDepth;
51 };
52
53 struct LineInfo {
54 unsigned instructionOffset;
55 int lineNumber;
56 };
57
58 struct CodeBlock {
59 CodeBlock(ScopeNode* ownerNode_, CodeType codeType_)
60 : ownerNode(ownerNode_)
61 , numTemporaries(0)
62 , numVars(0)
63 , numParameters(0)
64 , numLocals(0)
65 , needsFullScopeChain(ownerNode_->usesEval() || ownerNode_->needsClosure())
66 , usesEval(ownerNode_->usesEval())
67 , codeType(codeType_)
68 {
69 }
70
71 void dump(ExecState*) const;
72 int lineNumberForVPC(const Instruction*);
73 bool getHandlerForVPC(const Instruction* vPC, Instruction*& target, int& scopeDepth);
74 void mark();
75
76 ScopeNode* ownerNode;
77
78 int numTemporaries;
79 int numVars;
80 int numParameters;
81 int numLocals;
82 int thisRegister;
83 bool needsFullScopeChain;
84 bool usesEval;
85 CodeType codeType;
86
87 Vector<Instruction> instructions;
88
89 // Constant pool
90 Vector<Identifier> identifiers;
91 Vector<RefPtr<FuncDeclNode> > functions;
92 Vector<RefPtr<FuncExprNode> > functionExpressions;
93 Vector<JSValue*> jsValues;
94 Vector<RefPtr<RegExp> > regexps;
95 Vector<HandlerInfo> exceptionHandlers;
96 Vector<LineInfo> lineInfo;
97
98 private:
99 void dump(ExecState*, const Vector<Instruction>::const_iterator& begin, Vector<Instruction>::const_iterator&) const;
100 };
101
102 // Program code is not marked by any function, so we make the global object
103 // responsible for marking it.
104
105 struct ProgramCodeBlock : public CodeBlock {
106 ProgramCodeBlock(ScopeNode* ownerNode_, CodeType codeType_, JSGlobalObject* globalObject_)
107 : CodeBlock(ownerNode_, codeType_)
108 , globalObject(globalObject_)
109 {
110 globalObject->codeBlocks().add(this);
111 }
112
113 ~ProgramCodeBlock()
114 {
115 if (globalObject)
116 globalObject->codeBlocks().remove(this);
117 }
118
119 JSGlobalObject* globalObject; // For program and eval nodes, the global object that marks the constant pool.
120 };
121
122 struct EvalCodeBlock : public ProgramCodeBlock {
123 EvalCodeBlock(ScopeNode* ownerNode_, JSGlobalObject* globalObject_)
124 : ProgramCodeBlock(ownerNode_, EvalCode, globalObject_)
125 {
126 }
127 };
128
129} // namespace KJS
130
131#endif // CodeBlock_h
Note: See TracBrowser for help on using the repository browser.