Changeset 14799 in webkit for trunk/JavaScriptCore/kjs/context.h
- Timestamp:
- Jun 9, 2006, 8:57:13 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/context.h
r13821 r14799 4 4 * Copyright (C) 1999-2001 Harri Porten ([email protected]) 5 5 * Copyright (C) 2001 Peter Kelly ([email protected]) 6 * Copyright (C) 2003 Apple Computer, Inc.6 * Copyright (C) 2003, 2006 Apple Computer, Inc. 7 7 * 8 8 * This library is free software; you can redistribute it and/or … … 23 23 */ 24 24 25 #ifndef KJS_C ONTEXT_H26 #define KJS_C ONTEXT_H25 #ifndef KJS_Context_h 26 #define KJS_Context_h 27 27 28 28 #include "function.h" … … 30 30 namespace KJS { 31 31 32 /** 32 /** 33 33 * @short Execution context. 34 */ 35 class ContextImp { 34 * 35 * Represents an execution context, as specified by section 10 of the ECMA 36 * spec. 37 * 38 * An execution context contains information about the current state of the 39 * script - the scope for variable lookup, the value of "this", etc. A new 40 * execution context is entered whenever global code is executed (e.g. with 41 * Interpreter::evaluate()), a function is called (see 42 * Object::call()), or the builtin "eval" function is executed. 43 * 44 * Most inheritable functions in the KJS api take a ExecState pointer as 45 * their first parameter. This can be used to obtain a handle to the current 46 * execution context. 47 */ 48 class Context { 36 49 public: 37 ContextImp(JSObject* global, InterpreterImp*, JSObject* thisV, FunctionBodyNode* currentBody, 38 CodeType type = GlobalCode, ContextImp* callingContext = 0, FunctionImp* function = 0, const List* args = 0); 39 ~ContextImp(); 50 Context(JSObject* global, InterpreterImp*, JSObject* thisV, 51 FunctionBodyNode* currentBody, CodeType type = GlobalCode, 52 Context* callingContext = 0, FunctionImp* function = 0, const List* args = 0); 53 ~Context(); 40 54 55 /** 56 * Returns the scope chain for this execution context. This is used for 57 * variable lookup, with the list being searched from start to end until a 58 * variable is found. 59 * 60 * @return The execution context's scope chain 61 */ 62 const ScopeChain& scopeChain() const { return scope; } 63 64 /** 65 * Returns the variable object for the execution context. This contains a 66 * property for each variable declared in the execution context. 67 * 68 * @return The execution context's variable object 69 */ 70 JSObject* variableObject() const { return m_variable; } 71 void setVariableObject(JSObject* v) { m_variable = v; } 72 73 /** 74 * Returns the "this" value for the execution context. This is the value 75 * returned when a script references the special variable "this". It should 76 * always be an Object, unless application-specific code has passed in a 77 * different type. 78 * 79 * The object that is used as the "this" value depends on the type of 80 * execution context - for global contexts, the global object is used. For 81 * function objewcts, the value is given by the caller (e.g. in the case of 82 * obj.func(), obj would be the "this" value). For code executed by the 83 * built-in "eval" function, the this value is the same as the calling 84 * context. 85 * 86 * @return The execution context's "this" value 87 */ 88 JSObject* thisValue() const { return m_thisVal; } 89 90 /** 91 * Returns the context from which the current context was invoked. For 92 * global code this will be a null context (i.e. one for which 93 * isNull() returns true). You should check isNull() on the returned 94 * value before calling any of it's methods. 95 * 96 * @return The calling execution context 97 */ 98 Context* callingContext() { return m_callingContext; } 99 100 JSObject* activationObject() { return m_activation; } 101 CodeType codeType() { return m_codeType; } 41 102 FunctionBodyNode* currentBody() { return m_currentBody; } 103 FunctionImp* function() const { return m_function; } 104 const List* arguments() const { return m_arguments; } 42 105 43 const ScopeChain &scopeChain() const { return scope; } 44 CodeType codeType() { return m_codeType; } 45 JSObject *variableObject() const { return variable; } 46 void setVariableObject(JSObject *v) { variable = v; } 47 JSObject *thisValue() const { return thisVal; } 48 ContextImp *callingContext() { return _callingContext; } 49 JSObject *activationObject() { return activation; } 50 FunctionImp *function() const { return _function; } 51 const List *arguments() const { return _arguments; } 52 53 void pushScope(JSObject *s) { scope.push(s); } 106 void pushScope(JSObject* s) { scope.push(s); } 54 107 void popScope() { scope.pop(); } 55 LabelStack *seenLabels() { return &ls; } 56 108 LabelStack* seenLabels() { return &ls; } 57 109 58 110 void pushIteration() { m_iterationDepth++; } … … 67 119 68 120 private: 69 InterpreterImp *_interpreter; 70 ContextImp *_callingContext; 121 // Contexts are always stack-allocated, and the garbage collector 122 // marks the stack, so we don't need to protect the objects below from GC. 123 124 InterpreterImp* m_interpreter; 125 Context* m_callingContext; 71 126 FunctionBodyNode* m_currentBody; 72 127 73 FunctionImp *_function; 74 const List *_arguments; 75 // because ContextImp is always allocated on the stack, 76 // there is no need to protect various pointers from conservative 77 // GC since they will be caught by the conservative sweep anyway! 78 JSObject *activation; 128 FunctionImp* m_function; 129 const List* m_arguments; 130 JSObject* m_activation; 79 131 80 132 ScopeChain scope; 81 JSObject *variable;82 JSObject *thisVal;133 JSObject* m_variable; 134 JSObject* m_thisVal; 83 135 84 136 LabelStack ls;
Note:
See TracChangeset
for help on using the changeset viewer.