[webkit-help] Lifetime of ScriptState

Tim Mahoney tim.mahoney at me.com
Thu May 2 12:46:06 PDT 2013

After adding support for multiple script languages, I needed to make ScriptState into an abstract class. ScriptState used to be just a typedef of JSC::ExecState, so the lifetime of ScriptState was controlled by JSC. Now, the ScriptState for JavaScript is a wrapper around ExecState, so the lifetime of ScriptState is controlled by WebCore.

At the moment, I never destroy ScriptStates. This is obviously wrong, so I need to know when and how to destroy them. Here are two solutions I can think of:

A.) Rather than pass around ScriptState* pointers, I can pass around OwnPtr<ScriptState>. When that OwnPtr<ScriptState> is no longer referenced, it will be destroyed. This means that thousands of ScriptState objects may be allocated and destroyed very quickly.


B.) Only create one ScriptState for each ExecState and store them in a HashMap<ExecState*, ScriptState*>. Then clear all the ScriptStates for a Document when the Document is destroyed.

Solution A seems the most correct to me, but I'm wondering if creating and destroying all those objects will slow everything down. Any thoughts?


More information about the webkit-help mailing list