JavaScript bindings are unnecessarily checking for impossible empty JSValue arguments
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jun 2015 19:55:02 +0000 (19:55 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jun 2015 19:55:02 +0000 (19:55 +0000)
commitc24cdf7190a58d0e7de94379c5599330f48a1964
tree86b1269fbd71e3dfa311c7a88aef9739a3aebfa9
parentd5d0f2b900dce7140436cf28d8d6d0e654506ee5
JavaScript bindings are unnecessarily checking for impossible empty JSValue arguments
https://bugs.webkit.org/show_bug.cgi?id=145811

Reviewed by Antti Koivisto.

At some point, someone who didn't understand JSValue very well added checks for
isEmpty (and the function isEmpty itself) in JavaScript bindings. But the engine
never would pass an empty JSValue to a binding; that's used only inside the
engine itself. I think this was done by some Google V8 experts a while back, so
it's not entirely surprising they didn't understand this. But we don't want to
keep all that unneeded code.

* bindings/js/JSAudioTrackCustom.cpp:
(WebCore::JSAudioTrack::setKind): Removed the isEmpty clause here. I presume this
was copied and pasted from script-generated bindings. While I was at it, I used a
slightly more efficient code path that avoids doing a ref/deref on the string by
using auto&. That's trickier to do correctly for functions with more than one
argument, so I didn't do it in the bindings generator yet.
(WebCore::JSAudioTrack::setLanguage): Ditto.
* bindings/js/JSTextTrackCustom.cpp:
(WebCore::JSTextTrack::setKind): Ditto.
(WebCore::JSTextTrack::setLanguage): Ditto.
* bindings/js/JSVideoTrackCustom.cpp:
(WebCore::JSVideoTrack::setKind): Ditto.
(WebCore::JSVideoTrack::setLanguage): Ditto.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation): Use "=" syntax instead of constructor style syntax for
the argument processing. I think this is more readable.
(GenerateParametersCheck): For the enum code path, did the more efficient auto&
idiom to avoid ref/deref on a string. For the toExistingAtomicString path,
restructured so we don't have to check the flag indicating that something is atomic.
Later we could also avoid the ref/deref; added a FIXME about that.
(GetNativeType): Use String, not const String, for local variables. Sure, the
string is const, but so is every other local variable type we use! No need to be
wordy about it.
(JSValueToNative): Removed the uneeded calls to isEmpty. Since the call sites no
longer use construction syntax, used initializer syntax style for a couple classes
that are constructed with multiple arguments.

* bindings/scripts/test/JS/JSTestActiveDOMObject.cpp: Updated.
* bindings/scripts/test/JS/JSTestCustomNamedGetter.cpp: Ditto.
* bindings/scripts/test/JS/JSTestEventTarget.cpp: Ditto.
* bindings/scripts/test/JS/JSTestInterface.cpp: Ditto.
* bindings/scripts/test/JS/JSTestNamedConstructor.cpp: Ditto.
* bindings/scripts/test/JS/JSTestNondeterministic.cpp: Ditto.
* bindings/scripts/test/JS/JSTestObj.cpp: Ditto.
* bindings/scripts/test/JS/JSTestOverloadedConstructors.cpp: Ditto.
* bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.cpp: Ditto.
* bindings/scripts/test/JS/JSTestTypedefs.cpp: Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185373 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSAudioTrackCustom.cpp
Source/WebCore/bindings/js/JSTextTrackCustom.cpp
Source/WebCore/bindings/js/JSVideoTrackCustom.cpp
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSTestActiveDOMObject.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestCustomNamedGetter.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestEventTarget.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestInterface.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestNamedConstructor.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestNondeterministic.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestOverloadedConstructors.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestTypedefs.cpp