[Webkit-unassigned] [Bug 172481] New: [WebIDL] Overloaded functions unnecessarily duplicate argument checks
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Mon May 22 17:18:03 PDT 2017
https://bugs.webkit.org/show_bug.cgi?id=172481
Bug ID: 172481
Summary: [WebIDL] Overloaded functions unnecessarily duplicate
argument checks
Product: WebKit
Version: WebKit Nightly Build
Hardware: Unspecified
OS: Unspecified
Status: NEW
Severity: Normal
Priority: P2
Component: Bindings
Assignee: webkit-unassigned at lists.webkit.org
Reporter: sam at webkit.org
CC: cdumez at apple.com
Overloaded functions are currently unnecessarily duplicate argument checks. For example, let's take CanvasRenderingContext2d's stroke function. It has two overloads:
void stroke(DOMPath path);
void stroke();
This generates the main bindings function:
EncodedJSValue JSC_HOST_CALL jsCanvasRenderingContext2DPrototypeFunctionStroke(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
size_t argsCount = std::min<size_t>(1, state->argumentCount());
if (argsCount == 0) {
return jsCanvasRenderingContext2DPrototypeFunctionStroke2(state);
}
if (argsCount == 1) {
return jsCanvasRenderingContext2DPrototypeFunctionStroke1(state);
}
return throwVMTypeError(state, throwScope);
}
and then two the helpers, jsCanvasRenderingContext2DPrototypeFunctionStroke1 and jsCanvasRenderingContext2DPrototypeFunctionStroke2.
Taking a look at jsCanvasRenderingContext2DPrototypeFunctionStroke1, we see the argumentCount is once again checked, despite it already having been done in the main function:
static inline JSC::EncodedJSValue jsCanvasRenderingContext2DPrototypeFunctionStroke1Caller(JSC::ExecState* state, JSCanvasRenderingContext2D* castedThis, JSC::ThrowScope& throwScope)
{
UNUSED_PARAM(state);
UNUSED_PARAM(throwScope);
auto& impl = castedThis->wrapped();
if (UNLIKELY(state->argumentCount() < 1))
return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
auto path = convert<IDLInterface<DOMPath>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "path", "CanvasRenderingContext2D", "stroke", "DOMPath"); });
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
impl.stroke(*path);
return JSValue::encode(jsUndefined());
}
We could further improve things by taking advantage of the cases where disambiguation takes place, and retain the type information into the helpers.
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20170523/d9a6e7f2/attachment.html>
More information about the webkit-unassigned
mailing list