Bug 102552 - IndexedDB: Obtain ScriptState from IDL binding generator
Summary: IndexedDB: Obtain ScriptState from IDL binding generator
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on: 102739
Blocks: 45110
  Show dependency treegraph
 
Reported: 2012-11-16 12:43 PST by Michael Pruett
Modified: 2012-11-21 22:53 PST (History)
7 users (show)

See Also:


Attachments
Patch (4.17 KB, patch)
2012-11-16 14:27 PST, Michael Pruett
no flags Details | Formatted Diff | Diff
Patch (10.92 KB, patch)
2012-11-21 12:57 PST, Michael Pruett
haraken: review+
Details | Formatted Diff | Diff
Patch (10.85 KB, patch)
2012-11-21 17:13 PST, Michael Pruett
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Pruett 2012-11-16 12:43:56 PST
Currently when serializing a ScriptValue in IDBObjectStore::put(), the ScriptValue is serialized using the ScriptState provided by ScriptState::current(). In JSC there is no ScriptState::current(), and it will be necessary to obtain an ExecState from DOMRequestState to serialize the ScriptValue.
Comment 1 Michael Pruett 2012-11-16 14:27:05 PST
Created attachment 174760 [details]
Patch
Comment 2 Alec Flett 2012-11-16 15:08:53 PST
Comment on attachment 174760 [details]
Patch

This looks ok to me. I'd be curious what abarth thinks. I've always found it a little odd that SerializedScriptValue::deserialize takes a ScriptState and not something better. (In fact I wonder now if there's a way we can fix SerializedScriptValue rather than fix this here)
Comment 3 Michael Pruett 2012-11-16 15:29:26 PST
Another possible approach would be to update DOMRequestState to add a method to return the ScriptState* (presumably with ScriptState::forContext()); we could then use requestState.scriptState() for both V8 and JSC and skip adding the new serializeIDBValue() function.
Comment 4 Adam Barth 2012-11-17 09:57:46 PST
Can't you just add a CallWith=ScriptState to the IDL to get the script state from the bindings layer?
Comment 5 Michael Pruett 2012-11-19 14:24:33 PST
(In reply to comment #4)
> Can't you just add a CallWith=ScriptState to the IDL to get the script state from the bindings layer?

That solution would be ideal. However it seems that adding CallWith=ScriptState to a function causes the V8 binding generator to invoke the function with an EmptyScriptState rather than with ScriptState::current(). And at the beginning of ScriptValue::serialize(), a ScriptScope is created with this EmptyScriptState. Since the EmptyScriptState has a null v8::Context, the v8::Context::Scope in ScriptScope enters the null context, triggering an assertion failure in V8.
Comment 6 Adam Barth 2012-11-19 14:59:07 PST
> However it seems that adding CallWith=ScriptState to a function causes the V8 binding generator to invoke the function with an EmptyScriptState rather than with ScriptState::current().

That sounds like a bug in the code generator that we should fix.
Comment 7 Michael Pruett 2012-11-21 12:57:01 PST
Created attachment 175501 [details]
Patch
Comment 8 Michael Pruett 2012-11-21 13:00:46 PST
Now that the V8 binding generator has been updated in <https://bugs.webkit.org/show_bug.cgi?id=102739>, I've created a new patch which obtains the ScriptState from the IDL binding generator. Creating a new serializeIDBValue() utility function is no longer necessary.
Comment 9 Joshua Bell 2012-11-21 16:21:15 PST
Comment on attachment 175501 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=175501&action=review

IDB changes LGTM but would be nice to start off with consistent naming, i.e....

> Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp:136
> +    return put(IDBObjectStoreBackendInterface::AddOrUpdate, IDBAny::create(this), scriptState, value, key, ec);

^^^ "scriptState" vs.

> Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp:139
> +PassRefPtr<IDBRequest> IDBObjectStore::put(IDBObjectStoreBackendInterface::PutMode putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, PassRefPtr<IDBKey> prpKey, ExceptionCode& ec)

^^^ "state"
Comment 10 Kentaro Hara 2012-11-21 16:30:01 PST
Comment on attachment 175501 [details]
Patch

LGTM. Please address jsbell's comments before landing.
Comment 11 Michael Pruett 2012-11-21 17:13:52 PST
Created attachment 175550 [details]
Patch

I've changed variables previously named 'scriptState' to 'state' for the sake of consistency.
Comment 12 WebKit Review Bot 2012-11-21 20:35:21 PST
Comment on attachment 175550 [details]
Patch

Clearing flags on attachment: 175550

Committed r135471: <http://trac.webkit.org/changeset/135471>
Comment 13 WebKit Review Bot 2012-11-21 20:35:25 PST
All reviewed patches have been landed.  Closing bug.
Comment 14 Adam Barth 2012-11-21 22:53:59 PST
Comment on attachment 175550 [details]
Patch

Thanks for improving the code generator.  I think this patch came out very nicely this way.