WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
50081
Clean up IDBDatabase.transaction and add checks to IDBTransaction.objectStore
https://bugs.webkit.org/show_bug.cgi?id=50081
Summary
Clean up IDBDatabase.transaction and add checks to IDBTransaction.objectStore
Jeremy Orlow
Reported
2010-11-25 07:28:54 PST
Clean up IDBDatabase.transaction and add checks to IDBTransaction.objectStore
Attachments
Patch
(40.90 KB, patch)
2010-11-25 10:37 PST
,
Jeremy Orlow
no flags
Details
Formatted Diff
Diff
Patch
(40.88 KB, patch)
2010-11-26 03:22 PST
,
Jeremy Orlow
no flags
Details
Formatted Diff
Diff
Patch
(39.79 KB, patch)
2010-11-26 07:07 PST
,
Jeremy Orlow
no flags
Details
Formatted Diff
Diff
diff between patch 2 and 3
(6.76 KB, patch)
2010-11-26 07:09 PST
,
Jeremy Orlow
no flags
Details
Formatted Diff
Diff
Patch
(40.31 KB, patch)
2010-11-26 08:14 PST
,
Jeremy Orlow
no flags
Details
Formatted Diff
Diff
Patch
(40.49 KB, patch)
2010-11-26 08:25 PST
,
Jeremy Orlow
steveblock
: review+
Details
Formatted Diff
Diff
Show Obsolete
(5)
View All
Add attachment
proposed patch, testcase, etc.
Jeremy Orlow
Comment 1
2010-11-25 10:37:05 PST
Created
attachment 74891
[details]
Patch
Hans Wennborg
Comment 2
2010-11-25 11:35:45 PST
Comment on
attachment 74891
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=74891&action=review
> WebCore/bindings/v8/OptionsObject.cpp:30 > +#include <limits>
I think this should come last in the list of includes?
> WebCore/bindings/v8/OptionsObject.cpp:96 > +String OptionsObject::getKeyString(const String& key) const
Are we sure we don't want to make this return a bool that can be false to signal an option not being found, like the bool and integer getKey functions?
> WebCore/storage/IDBDatabase.cpp:29 > +#include <limits>
I think this should be last.
Jeremy Orlow
Comment 3
2010-11-25 11:42:47 PST
(In reply to
comment #2
)
> (From update of
attachment 74891
[details]
) > View in context:
https://bugs.webkit.org/attachment.cgi?id=74891&action=review
> > > WebCore/bindings/v8/OptionsObject.cpp:30 > > +#include <limits> > > I think this should come last in the list of includes? > > > WebCore/bindings/v8/OptionsObject.cpp:96 > > +String OptionsObject::getKeyString(const String& key) const > > Are we sure we don't want to make this return a bool that can be false to signal an option not being found, like the bool and integer getKey functions?
I went back and forth, but I found the usage of this cleaner. If something cares to distinguish between a key being null and/or undefined vs a string, they should probably do that themself anyway. I think the ideal would actually be for primitives to be boxed in some sort of object so I can return a null object to signal nothing. But since not, I somewhat think this is best....but like I said, I went back and forth.
> > WebCore/storage/IDBDatabase.cpp:29 > > +#include <limits> > > I think this should be last.
I'll try it, but I think the style bot was yelling at me.
Jeremy Orlow
Comment 4
2010-11-25 11:52:49 PST
Comment on
attachment 74891
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=74891&action=review
> WebCore/bindings/v8/OptionsObject.cpp:108 > +RefPtr<DOMStringList> OptionsObject::getKeyDOMStringList(const String& key) const
Should be passRefPtr
Jeremy Orlow
Comment 5
2010-11-26 03:22:00 PST
Created
attachment 74912
[details]
Patch
Steve Block
Comment 6
2010-11-26 05:11:51 PST
Comment on
attachment 74912
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=74912&action=review
> WebCore/bindings/v8/OptionsObject.cpp:76 > +bool OptionsObject::getKeyInteger(const String& key, int64_t& value) const
Does JSC have an equivalent Integer type? If not, you might want to call this getKeyInt64 for compatibility.
> WebCore/bindings/v8/OptionsObject.cpp:82 > + if (!v8Value->IsNumber())
Shouldn't you be testing for int64/Integer, rather than Number?
> WebCore/bindings/v8/OptionsObject.cpp:96 > +String OptionsObject::getKeyString(const String& key) const
I agree with Hans that this should return a boolean and have the string as an out param. I think that wanting to distinguish between a non-string object and an empty string is a common use case. At the very least, if you want the API to return a default value (here the empty string) if the type is incorrect, we should be consistent in doing so for all methods.
> WebCore/bindings/v8/OptionsObject.h:49 > + PassRefPtr<DOMStringList> getKeyDOMStringList(const String& key) const;
It looks like all of these methods don't do any coercion and will fail if the property doesn't have the expected type. This isn't what I'd expect for JS, so might be worth a comment.
> WebCore/storage/IDBDatabase.cpp:44 > +const unsigned long defaultTimeout = 0; // Infinite.
I think the accepted style is to avoid 'magic values' like this. See
https://bugs.webkit.org/show_bug.cgi?id=27254#c5
Andrei Popescu
Comment 7
2010-11-26 05:23:25 PST
> result = evalAndLog("webkitIndexedDB.open('name', 'description')");
No need to pass description anymore.
> if (!v8Value->IsNumber())
I wonder if we should just let the VM give us a number instead? You could do: v8::Local<v8::Number> number = v8value->ToNumber(); if (number.IsEmpty()) { // Could not get a number out of the JS value. return false; } Same for the other methods?
Andrei Popescu
Comment 8
2010-11-26 05:25:25 PST
(In reply to
comment #7
)
> > result = evalAndLog("webkitIndexedDB.open('name', 'description')"); > > No need to pass description anymore. > > > if (!v8Value->IsNumber()) > > I wonder if we should just let the VM give us a number instead? You could do: > > v8::Local<v8::Number> number = v8value->ToNumber(); > if (number.IsEmpty()) { > // Could not get a number out of the JS value. > return false; > } > > > Same for the other methods?
To clarify, looking at the spec, I don't think the language in the spec document calls for this strict type checking. Also, we had a similar discussion for Geolocation and here's what Darin had to say about the same issue:
https://bugs.webkit.org/show_bug.cgi?id=27254#c7
Jeremy Orlow
Comment 9
2010-11-26 05:33:48 PST
(In reply to
comment #6
)
> (From update of
attachment 74912
[details]
) > View in context:
https://bugs.webkit.org/attachment.cgi?id=74912&action=review
> > > WebCore/bindings/v8/OptionsObject.cpp:76 > > +bool OptionsObject::getKeyInteger(const String& key, int64_t& value) const > > Does JSC have an equivalent Integer type? If not, you might want to call this getKeyInt64 for compatibility.
Apparently not.
> > WebCore/bindings/v8/OptionsObject.cpp:82 > > + if (!v8Value->IsNumber()) > > Shouldn't you be testing for int64/Integer, rather than Number?
There is no such thing. I guess the portable solution is probably to just extract the double and do all the rest of the work myself.
> > WebCore/bindings/v8/OptionsObject.cpp:96 > > +String OptionsObject::getKeyString(const String& key) const > > I agree with Hans that this should return a boolean and have the string as an out param. I think that wanting to distinguish between a non-string object and an empty string is a common use case.
Not sure I agree, but OK, I"ll do it.
> At the very least, if you want the API to return a default value (here the empty string) if the type is incorrect, we should be consistent in doing so for all methods.
I think this would be the ideal, but it's clearly not possible for non pointer or string types.
> > WebCore/bindings/v8/OptionsObject.h:49 > > + PassRefPtr<DOMStringList> getKeyDOMStringList(const String& key) const; > > It looks like all of these methods don't do any coercion and will fail if the property doesn't have the expected type. This isn't what I'd expect for JS, so might be worth a comment.
In what cases do you think we're doing the wrong thing? I think null/undefined should be treated as no value present. Doing something like {unique: someObject} evaluating to true rather than the default doesn't seem that useful. I did think about this, but I couldn't think of a case where coercion is better than what I have here.
> > WebCore/storage/IDBDatabase.cpp:44 > > +const unsigned long defaultTimeout = 0; // Infinite. > > I think the accepted style is to avoid 'magic values' like this. See
https://bugs.webkit.org/show_bug.cgi?id=27254#c5
This is not a change. Just moving what was there before. There's a lot of existing code that uses this and the spec doesn't actually say (as far as I can tell) how to specify "infinite" so I'd like to punt this until we figure it out at the spec side. I can add a FIXME. Please do review the others while we nail this down as none of these issues should prohibit a review.
Jeremy Orlow
Comment 10
2010-11-26 07:06:49 PST
(In reply to
comment #9
)
> (In reply to
comment #6
) > > (From update of
attachment 74912
[details]
[details]) > > View in context:
https://bugs.webkit.org/attachment.cgi?id=74912&action=review
> > > > > WebCore/bindings/v8/OptionsObject.cpp:76 > > > +bool OptionsObject::getKeyInteger(const String& key, int64_t& value) const > > > > Does JSC have an equivalent Integer type? If not, you might want to call this getKeyInt64 for compatibility. > > Apparently not.
Switched things over to using int32, which both support and which should meet the needs for now. In the future, timeout should use a double. I've added a FIXME for this.
> > > WebCore/bindings/v8/OptionsObject.cpp:82 > > > + if (!v8Value->IsNumber()) > > > > Shouldn't you be testing for int64/Integer, rather than Number? > > There is no such thing. I guess the portable solution is probably to just extract the double and do all the rest of the work myself. > > > > WebCore/bindings/v8/OptionsObject.cpp:96 > > > +String OptionsObject::getKeyString(const String& key) const > > > > I agree with Hans that this should return a boolean and have the string as an out param. I think that wanting to distinguish between a non-string object and an empty string is a common use case. > > Not sure I agree, but OK, I"ll do it.
done
> > At the very least, if you want the API to return a default value (here the empty string) if the type is incorrect, we should be consistent in doing so for all methods. > > I think this would be the ideal, but it's clearly not possible for non pointer or string types. > > > > WebCore/bindings/v8/OptionsObject.h:49 > > > + PassRefPtr<DOMStringList> getKeyDOMStringList(const String& key) const; > > > > It looks like all of these methods don't do any coercion and will fail if the property doesn't have the expected type. This isn't what I'd expect for JS, so might be worth a comment. > > In what cases do you think we're doing the wrong thing? I think null/undefined should be treated as no value present. Doing something like {unique: someObject} evaluating to true rather than the default doesn't seem that useful. I did think about this, but I couldn't think of a case where coercion is better than what I have here.
As discussed, yeah, this is the right thing to do. Made much more liberal.
> > > WebCore/storage/IDBDatabase.cpp:44 > > > +const unsigned long defaultTimeout = 0; // Infinite. > > > > I think the accepted style is to avoid 'magic values' like this. See
https://bugs.webkit.org/show_bug.cgi?id=27254#c5
> > This is not a change. Just moving what was there before. There's a lot of existing code that uses this and the spec doesn't actually say (as far as I can tell) how to specify "infinite" so I'd like to punt this until we figure it out at the spec side. I can add a FIXME.
added
Jeremy Orlow
Comment 11
2010-11-26 07:07:42 PST
Created
attachment 74936
[details]
Patch
Jeremy Orlow
Comment 12
2010-11-26 07:09:35 PST
Created
attachment 74937
[details]
diff between patch 2 and 3
Andrei Popescu
Comment 13
2010-11-26 07:35:47 PST
LGTM
Eric Seidel (no email)
Comment 14
2010-11-26 07:38:57 PST
Attachment 74936
[details]
did not build on chromium: Build output:
http://queues.webkit.org/results/6357066
Steve Block
Comment 15
2010-11-26 08:01:38 PST
Comment on
attachment 74936
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=74936&action=review
In getKey(), are you sure that Has(key) will return false if the caller explicitly passes undefined? Geolocation checks for an undefined value even if Has(key)/Get(key) returns a non-empty value. It looks like one of the two cases is wrong.
> WebCore/bindings/v8/OptionsObject.cpp:68 > ASSERT(!v8Bool.IsEmpty());
I don't think this is safe. If the JavaScript property's valueOf() method throws an exception, v8Bool will be empty. See fast/dom/Geolocation/script-tests/argument-types.js. On a similar note, are you sure that calling Has(key) then ASSERT(!Get(key).IsEmpty()) is safe in getKey() in the case where the options object's property getter throws?
> WebCore/bindings/v8/OptionsObject.cpp:109 > + return 0;
Shouldn't you just call v8ValueToWebCoreString(), as in getKeyString(), rather than checking IsString()?
Jeremy Orlow
Comment 16
2010-11-26 08:09:27 PST
(In reply to
comment #15
)
> (From update of
attachment 74936
[details]
) > View in context:
https://bugs.webkit.org/attachment.cgi?id=74936&action=review
> > In getKey(), are you sure that Has(key) will return false if the caller explicitly passes undefined? Geolocation checks for an undefined value even if Has(key)/Get(key) returns a non-empty value. It looks like one of the two cases is wrong.
I don't know for sure, and it's not easy to look at the code. Will add extra check and fixme to look into it.
> > WebCore/bindings/v8/OptionsObject.cpp:68 > > ASSERT(!v8Bool.IsEmpty()); > > I don't think this is safe. If the JavaScript property's valueOf() method throws an exception, v8Bool will be empty. See fast/dom/Geolocation/script-tests/argument-types.js.
made these if, return false's.
> On a similar note, are you sure that calling Has(key) then ASSERT(!Get(key).IsEmpty()) is safe in getKey() in the case where the options object's property getter throws?
no, will make it more conservative.
> > WebCore/bindings/v8/OptionsObject.cpp:109 > > + return 0; > > Shouldn't you just call v8ValueToWebCoreString(), as in getKeyString(), rather than checking IsString()?
done
Jeremy Orlow
Comment 17
2010-11-26 08:14:02 PST
Created
attachment 74940
[details]
Patch
Jeremy Orlow
Comment 18
2010-11-26 08:25:55 PST
Created
attachment 74942
[details]
Patch
Jeremy Orlow
Comment 19
2010-11-26 08:31:00 PST
Committed
r72765
: <
http://trac.webkit.org/changeset/72765
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug