Changeset 15437 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jul 14, 2006, 3:39:58 PM (19 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/APICast.h
r15376 r15437 41 41 42 42 inline KJS::ExecState* toJS(JSContextRef c) 43 { 44 return reinterpret_cast<KJS::ExecState*>(const_cast<__JSContext*>(c)); 45 } 46 47 inline KJS::ExecState* toJS(JSGlobalContextRef c) 43 48 { 44 49 return reinterpret_cast<KJS::ExecState*>(c); -
trunk/JavaScriptCore/API/JSBase.h
r15428 r15437 33 33 34 34 /*! @typedef JSContextRef A JavaScript execution context. Holds the global object and other execution state. */ 35 typedef struct __JSContext* JSContextRef; 35 typedef const struct __JSContext* JSContextRef; 36 37 /*! @typedef JSGlobalContextRef A global JavaScript execution context. A JSGlobalContext is a JSContext. */ 38 typedef struct __JSContext* JSGlobalContextRef; 39 36 40 /*! @typedef JSString A UTF16 character buffer. The fundamental string representation in JavaScript. */ 37 41 typedef struct __JSString* JSStringRef; 42 38 43 /*! @typedef JSClassRef A JavaScript class. Used with JSObjectMake to construct objects with custom behavior. */ 39 44 typedef struct __JSClass* JSClassRef; 45 40 46 /*! @typedef JSPropertyListRef A JavaScript property list. Used for listing the properties in an object so they can be enumerated. */ 41 47 typedef struct __JSPropertyList* JSPropertyListRef; 48 42 49 /*! @typedef JSPropertyEnumeratorRef A JavaScript property enumerator. Used for enumerating the properties in an object. */ 43 50 typedef struct __JSPropertyEnumerator* JSPropertyEnumeratorRef; … … 48 55 /*! @typedef JSValueRef A JavaScript value. The base type for all JavaScript values, and polymorphic functions on them. */ 49 56 typedef const struct __JSValue* JSValueRef; 57 50 58 /*! @typedef JSObjectRef A JavaScript object. A JSObject is a JSValue. */ 51 59 typedef struct __JSValue* JSObjectRef; -
trunk/JavaScriptCore/API/JSContextRef.cpp
r15428 r15437 35 35 using namespace KJS; 36 36 37 JS ContextRef JSContextCreate(JSClassRef globalObjectClass)37 JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass) 38 38 { 39 39 JSLock lock; … … 47 47 48 48 Interpreter* interpreter = new Interpreter(globalObject); // adds the built-in object prototype to the global object 49 return toRef(interpreter->globalExec()); 49 JSGlobalContextRef context = reinterpret_cast<JSGlobalContextRef>(interpreter->globalExec()); 50 return JSGlobalContextRetain(context); 50 51 } 51 52 52 void JSContextDestroy(JSContextRef context)53 JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef context) 53 54 { 54 55 JSLock lock; 55 56 ExecState* exec = toJS(context); 56 delete exec->dynamicInterpreter(); 57 exec->dynamicInterpreter()->ref(); 58 return context; 59 } 60 61 void JSGlobalContextRelease(JSGlobalContextRef context) 62 { 63 JSLock lock; 64 ExecState* exec = toJS(context); 65 exec->dynamicInterpreter()->deref(); 57 66 } 58 67 -
trunk/JavaScriptCore/API/JSContextRef.h
r15428 r15437 39 39 /*! 40 40 @function 41 @abstract Creates a JavaScript execution context.42 @discussion JS ContextCreate allocates a global object and populates it with all the41 @abstract Creates a global JavaScript execution context. 42 @discussion JSGlobalContextCreate allocates a global object and populates it with all the 43 43 built-in JavaScript objects, such as Object, Function, String, and Array. 44 @param globalObjectClass The class to use when creating the JSContext's global object.45 PassNULL to use the default object class.46 @result A JS Context with a global object of class globalObjectClass.44 @param globalObjectClass The class to use when creating the global object. Pass 45 NULL to use the default object class. 46 @result A JSGlobalContext with a global object of class globalObjectClass. 47 47 */ 48 JS ContextRef JSContextCreate(JSClassRef globalObjectClass);48 JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass); 49 49 50 50 /*! 51 51 @function 52 @abstract Destroys a JavaScript execution context, freeing its resources. 53 @param context The JSContext to destroy. 52 @abstract Retains a global JavaScript execution context. 53 @param context The JSGlobalContext to retain. 54 @result A JSGlobalContext that is the same as context. 54 55 */ 55 void JSContextDestroy(JSContextRef context);56 JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef context); 56 57 57 58 /*! 58 59 @function 59 @abstract Gets the global object of a JavaScript execution context. 60 @param context The JSContext whose global object you want to get. 61 @result context's global object. 60 @abstract Releases a global JavaScript execution context. 61 @param context The JSGlobalContext to release. 62 */ 63 void JSGlobalContextRelease(JSGlobalContextRef context); 64 65 /*! 66 @function 67 @abstract Gets the global object of a JavaScript execution context. 68 @param context The JSContext whose global object you want to get. 69 @result context's global object. 62 70 */ 63 71 JSObjectRef JSContextGetGlobalObject(JSContextRef context); -
trunk/JavaScriptCore/API/JSStringRef.h
r15400 r15437 111 111 @param string The source JSString. 112 112 @param buffer The destination byte buffer into which to copy a null-terminated 113 UTF8 string representation of string. The buffer must be at least bufferSize 114 bytes in size. On return, buffer contains a UTF8 string representation of string. 115 If bufferSize is too small, buffer will contain only partial results. 113 UTF8 representation of string. On return, buffer contains a UTF8 string 114 representation of string. If bufferSize is too small, buffer will contain only 115 partial results. If buffer is not at least bufferSize bytes in size, 116 behavior is undefined. 116 117 @param bufferSize The size of the external buffer in bytes. 117 118 @result The number of bytes written into buffer (including the null-terminator byte). -
trunk/JavaScriptCore/API/minidom.c
r15404 r15437 37 37 UNUSED_PARAM(argv); 38 38 39 JS ContextRef context = JSContextCreate(NULL);39 JSGlobalContextRef context = JSGlobalContextCreate(NULL); 40 40 JSObjectRef globalObject = JSContextGetGlobalObject(context); 41 41 … … 74 74 #endif 75 75 76 JS ContextDestroy(context);76 JSGlobalContextRelease(context); 77 77 printf("PASS: Program exited normally.\n"); 78 78 return 0; -
trunk/JavaScriptCore/API/testapi.c
r15404 r15437 35 35 #include <math.h> 36 36 37 static JS ContextRef context = 0;37 static JSGlobalContextRef context = 0; 38 38 39 39 static void assertEqualsAsBoolean(JSValueRef value, bool expectedValue) … … 302 302 UNUSED_PARAM(argv); 303 303 304 context = JS ContextCreate(NULL);304 context = JSGlobalContextCreate(NULL); 305 305 306 306 JSObjectRef globalObject = JSContextGetGlobalObject(context); … … 605 605 JSStringRelease(badSyntax); 606 606 607 JS ContextDestroy(context);607 JSGlobalContextRelease(context); 608 608 printf("PASS: Program exited normally.\n"); 609 609 return 0; -
trunk/JavaScriptCore/ChangeLog
r15434 r15437 1 2006-07-14 Geoffrey Garen <[email protected]> 2 3 Reviewed by Maciej. 4 5 - Implemented ref-counting of JSContexts by splitting into two datatypes: 6 JSGlobalContext, which you can create/retain/release, and JSContext, which 7 you can't. 8 9 Internally, you retain a JSGlobalContext/ExecState by retaining its 10 interpreter, which, in the case of a global ExecState, owns it. 11 12 - Also made ~Interpreter() protected to catch places where Interpreter 13 is manually deleted. (Can't make it private because some crazy fool 14 decided it would be a good idea to subclass Interpreter in other frameworks. 15 I pity da fool.) 16 17 * API/APICast.h: 18 (toJS): Added cast for new JSGlobalContext 19 * API/JSStringRef.h: Changed vague "you must" language to more specific 20 (but, ultimately, equally vague) "behavior is undefined if you don't" 21 language. 22 (KJS::Interpreter::Interpreter): Factored more common initialization into 23 init() 24 * kjs/interpreter.h: 25 (KJS::Interpreter::ref): new 26 (KJS::Interpreter::deref): new 27 (KJS::Interpreter::refCount): new 28 * kjs/testkjs.cpp: 29 (doIt): Ref-count the interpreter. 30 1 31 2006-07-14 Maciej Stachowiak <[email protected]> 2 32 -
trunk/JavaScriptCore/JavaScriptCore.exp
r15404 r15437 6 6 _JSClassRelease 7 7 _JSClassRetain 8 _JSContextCreate9 _JSContextDestroy10 8 _JSContextGetGlobalObject 11 9 _JSEvaluateScript 12 10 _JSGarbageCollect 11 _JSGlobalContextCreate 12 _JSGlobalContextRelease 13 _JSGlobalContextRetain 13 14 _JSObjectCallAsConstructor 14 15 _JSObjectCallAsFunction -
trunk/JavaScriptCore/kjs/interpreter.cpp
r15224 r15437 208 208 209 209 Interpreter::Interpreter(JSObject* globalObject) 210 : m_timeoutTime(0) 211 , m_globalExec(this, 0) 210 : m_globalExec(this, 0) 212 211 , m_globalObject(globalObject) 213 , m_argumentsPropertyName(&argumentsPropertyName)214 , m_specialPrototypePropertyName(&specialPrototypePropertyName)215 , m_timeoutChecker(0)216 , m_timedOut(false)217 , m_startTimeoutCheckCount(0)218 , m_pauseTimeoutCheckCount(0)219 212 { 220 213 init(); … … 222 215 223 216 Interpreter::Interpreter() 224 : m_timeoutTime(0) 225 , m_globalExec(this, 0) 217 : m_globalExec(this, 0) 226 218 , m_globalObject(new JSObject()) 227 , m_argumentsPropertyName(&argumentsPropertyName)228 , m_specialPrototypePropertyName(&specialPrototypePropertyName)229 , m_timeoutChecker(0)230 , m_timedOut(false)231 , m_startTimeoutCheckCount(0)232 , m_pauseTimeoutCheckCount(0)233 219 { 234 220 init(); … … 239 225 JSLock lock; 240 226 227 m_refCount = 0; 228 m_timeoutTime = 0; 241 229 m_recursion = 0; 242 230 m_debugger= 0; 243 231 m_context = 0; 232 m_timedOut = false; 233 m_timeoutChecker = 0; 234 m_startTimeoutCheckCount = 0; 235 m_pauseTimeoutCheckCount = 0; 244 236 m_compatMode = NativeMode; 237 m_argumentsPropertyName = &argumentsPropertyName; 238 m_specialPrototypePropertyName = &specialPrototypePropertyName; 245 239 246 240 interpreterMap().set(m_globalObject, this); -
trunk/JavaScriptCore/kjs/interpreter.h
r15163 r15437 75 75 */ 76 76 Interpreter(); 77 virtual ~Interpreter();78 77 79 78 /** … … 338 337 bool checkTimeout(); 339 338 339 void ref() { ++m_refCount; } 340 void deref() { if (--m_refCount <= 0) delete this; } 341 int refCount() const { return m_refCount; } 342 340 343 protected: 344 virtual ~Interpreter(); // only deref should delete us 341 345 virtual bool shouldInterruptScript() const { return true; } 346 342 347 long m_timeoutTime; 343 348 … … 359 364 */ 360 365 Interpreter operator=(const Interpreter&); 366 367 int m_refCount; 361 368 362 369 ExecState m_globalExec; -
trunk/JavaScriptCore/kjs/testkjs.cpp
r14457 r15437 213 213 214 214 // create interpreter 215 Interpreter interp(global);215 RefPtr<Interpreter> interp = new Interpreter(global); 216 216 // add debug() function 217 global->put(interp .globalExec(), "debug", new TestFunctionImp(TestFunctionImp::Debug, 1));217 global->put(interp->globalExec(), "debug", new TestFunctionImp(TestFunctionImp::Debug, 1)); 218 218 // add "print" for compatibility with the mozilla js shell 219 global->put(interp .globalExec(), "print", new TestFunctionImp(TestFunctionImp::Print, 1));219 global->put(interp->globalExec(), "print", new TestFunctionImp(TestFunctionImp::Print, 1)); 220 220 // add "quit" for compatibility with the mozilla js shell 221 global->put(interp .globalExec(), "quit", new TestFunctionImp(TestFunctionImp::Quit, 0));221 global->put(interp->globalExec(), "quit", new TestFunctionImp(TestFunctionImp::Quit, 0)); 222 222 // add "gc" for compatibility with the mozilla js shell 223 global->put(interp .globalExec(), "gc", new TestFunctionImp(TestFunctionImp::GC, 0));223 global->put(interp->globalExec(), "gc", new TestFunctionImp(TestFunctionImp::GC, 0)); 224 224 // add "version" for compatibility with the mozilla js shell 225 global->put(interp .globalExec(), "version", new TestFunctionImp(TestFunctionImp::Version, 1));226 global->put(interp .globalExec(), "run", new TestFunctionImp(TestFunctionImp::Run, 1));225 global->put(interp->globalExec(), "version", new TestFunctionImp(TestFunctionImp::Version, 1)); 226 global->put(interp->globalExec(), "run", new TestFunctionImp(TestFunctionImp::Run, 1)); 227 227 228 228 Interpreter::setShouldPrintExceptions(true); … … 239 239 } 240 240 241 Completion completion = interp .evaluate(fileName, 0, script);241 Completion completion = interp->evaluate(fileName, 0, script); 242 242 success = success && completion.complType() != Throw; 243 243 free(script);
Note:
See TracChangeset
for help on using the changeset viewer.