Skip to content

Commit

Permalink
binding: Retires utilities in V8Binding.h for throwing arity errors.
Browse files Browse the repository at this point in the history
Retires the following functions.
  setArityTypeError
  createMinimumArityTypeErrorForMethod
  createMinimumArityTypeErrorForConstructor
  setMinimumArityTypeError

BUG=

Review-Url: https://codereview.chromium.org/2334183002
Cr-Commit-Position: refs/heads/master@{#418225}
  • Loading branch information
yuki3 authored and Commit bot committed Sep 13, 2016
1 parent 91fecd4 commit c42a74b
Show file tree
Hide file tree
Showing 84 changed files with 223 additions and 246 deletions.
20 changes: 0 additions & 20 deletions third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,6 @@

namespace blink {

void setArityTypeError(ExceptionState& exceptionState, const char* valid, unsigned provided)
{
exceptionState.throwTypeError(ExceptionMessages::invalidArity(valid, provided));
}

v8::Local<v8::Value> createMinimumArityTypeErrorForMethod(v8::Isolate* isolate, const char* method, const char* type, unsigned expected, unsigned provided)
{
return V8ThrowException::createTypeError(isolate, ExceptionMessages::failedToExecute(method, type, ExceptionMessages::notEnoughArguments(expected, provided)));
}

v8::Local<v8::Value> createMinimumArityTypeErrorForConstructor(v8::Isolate* isolate, const char* type, unsigned expected, unsigned provided)
{
return V8ThrowException::createTypeError(isolate, ExceptionMessages::failedToConstruct(type, ExceptionMessages::notEnoughArguments(expected, provided)));
}

void setMinimumArityTypeError(ExceptionState& exceptionState, unsigned expected, unsigned provided)
{
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(expected, provided));
}

NodeFilter* toNodeFilter(v8::Local<v8::Value> callback, v8::Local<v8::Object> creationContext, ScriptState* scriptState)
{
if (callback->IsNull())
Expand Down
6 changes: 0 additions & 6 deletions third_party/WebKit/Source/bindings/core/v8/V8Binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ struct V8TypeOf {
typedef void Type;
};

// Helpers for throwing JavaScript TypeErrors for arity mismatches.
CORE_EXPORT void setArityTypeError(ExceptionState&, const char* valid, unsigned provided);
CORE_EXPORT v8::Local<v8::Value> createMinimumArityTypeErrorForMethod(v8::Isolate*, const char* method, const char* type, unsigned expected, unsigned provided);
CORE_EXPORT v8::Local<v8::Value> createMinimumArityTypeErrorForConstructor(v8::Isolate*, const char* type, unsigned expected, unsigned provided);
CORE_EXPORT void setMinimumArityTypeError(ExceptionState&, unsigned expected, unsigned provided);

template<typename CallbackInfo, typename S>
inline void v8SetReturnValue(const CallbackInfo& info, const v8::Persistent<S>& handle)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void V8CustomEvent::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>&
{
ExceptionState exceptionState(ExceptionState::ConstructionContext, "CustomEvent", info.Holder(), info.GetIsolate());
if (UNLIKELY(info.Length() < 1)) {
setMinimumArityTypeError(exceptionState, 1, info.Length());
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,26 @@ namespace blink {

void V8IntersectionObserver::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionContext, "IntersectionObserver");

if (UNLIKELY(info.Length() < 1)) {
V8ThrowException::throwException(info.GetIsolate(), createMinimumArityTypeErrorForMethod(info.GetIsolate(), "createIntersectionObserver", "Intersection", 1, info.Length()));
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
return;
}

v8::Local<v8::Object> wrapper = info.Holder();

if (!info[0]->IsFunction()) {
V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToExecute("createIntersectionObserver", "Intersection", "The callback provided as parameter 1 is not a function."));
exceptionState.throwTypeError("The callback provided as parameter 1 is not a function.");
return;
}

if (info.Length() > 1 && !isUndefinedOrNull(info[1]) && !info[1]->IsObject()) {
V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToExecute("createIntersectionObserver", "Intersection", "IntersectionObserverInit (parameter 2) is not an object."));
exceptionState.throwTypeError("parameter 2 ('options') is not an object.");
return;
}

IntersectionObserverInit intersectionObserverInit;
ExceptionState exceptionState(ExceptionState::ConstructionContext, "Intersection", info.Holder(), info.GetIsolate());
V8IntersectionObserverInit::toImpl(info.GetIsolate(), info[1], intersectionObserverInit, exceptionState);
if (exceptionState.hadException())
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "bindings/core/v8/V8PerformanceObserver.h"

#include "bindings/core/v8/ExceptionMessages.h"
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8DOMWrapper.h"
#include "bindings/core/v8/V8GCController.h"
Expand All @@ -19,7 +18,7 @@ namespace blink {
void V8PerformanceObserver::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
if (UNLIKELY(info.Length() < 1)) {
V8ThrowException::throwException(info.GetIsolate(), createMinimumArityTypeErrorForMethod(info.GetIsolate(), "createPerformanceObserver", "Performance", 1, info.Length()));
V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToConstruct("PerformanceObserver", ExceptionMessages::notEnoughArguments(1, info.Length())));
return;
}

Expand All @@ -28,7 +27,7 @@ void V8PerformanceObserver::constructorCustom(const v8::FunctionCallbackInfo<v8:
Performance* performance = nullptr;
DOMWindow* window = toDOMWindow(wrapper->CreationContext());
if (!window) {
V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToExecute("createPerformanceObserver", "Performance", "No \"window\" in current context."));
V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToConstruct("PerformanceObserver", "No 'window' in current context."));
return;
}
performance = DOMWindowPerformance::performance(*window);
Expand All @@ -37,7 +36,7 @@ void V8PerformanceObserver::constructorCustom(const v8::FunctionCallbackInfo<v8:
PerformanceObserverCallback* callback;
{
if (info.Length() <= 0 || !info[0]->IsFunction()) {
V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToExecute("createPerformanceObserver", "Performance", "The callback provided as parameter 1 is not a function."));
V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToConstruct("PerformanceObserver", "The callback provided as parameter 1 is not a function."));
return;
}
callback = V8PerformanceObserverCallback::create(v8::Local<v8::Function>::Cast(info[0]), wrapper, ScriptState::current(info.GetIsolate()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
{
ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage", "Window", info.Holder(), info.GetIsolate());
if (UNLIKELY(info.Length() < 2)) {
setMinimumArityTypeError(exceptionState, 2, info.Length());
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, info.Length()));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void V8ServiceWorkerMessageEventInternal::constructorCustom(const v8::FunctionCa
{
ExceptionState exceptionState(ExceptionState::ConstructionContext, V8TypeOf<EventType>::Type::wrapperTypeInfo.interfaceName, info.Holder(), info.GetIsolate());
if (UNLIKELY(info.Length() < 1)) {
setMinimumArityTypeError(exceptionState, 1, info.Length());
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@ namespace blink {

void V8IDBObserver::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionContext, "IDBObserver");

if (UNLIKELY(info.Length() < 1)) {
V8ThrowException::throwException(info.GetIsolate(), createMinimumArityTypeErrorForConstructor(info.GetIsolate(), "IDBObserver", 1, info.Length()));
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
return;
}

v8::Local<v8::Object> wrapper = info.Holder();

if (!info[0]->IsFunction()) {
V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToConstruct("IDBObserver", "The callback provided as parameter 1 is not a function."));
exceptionState.throwTypeError("The callback provided as parameter 1 is not a function.");
return;
}

if (info.Length() > 1 && !isUndefinedOrNull(info[1]) && !info[1]->IsObject()) {
V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToConstruct("IDBObserver", "IDBObserverInit (parameter 2) is not an object."));
exceptionState.throwTypeError("parameter 2 ('options') is not an object.");
return;
}

IDBObserverInit idbObserverInit;
ExceptionState exceptionState(ExceptionState::ConstructionContext, "IDBObserver", info.Holder(), info.GetIsolate());
V8IDBObserverInit::toImpl(info.GetIsolate(), info[1], idbObserverInit, exceptionState);
if (exceptionState.hadException())
return;
Expand Down
2 changes: 1 addition & 1 deletion third_party/WebKit/Source/bindings/scripts/v8_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@


INTERFACE_H_INCLUDES = frozenset([
'bindings/core/v8/GeneratedCodeHelper.h',
'bindings/core/v8/ScriptWrappable.h',
'bindings/core/v8/ToV8.h',
'bindings/core/v8/V8Binding.h',
Expand All @@ -60,6 +59,7 @@
])
INTERFACE_CPP_INCLUDES = frozenset([
'bindings/core/v8/ExceptionState.h',
'bindings/core/v8/GeneratedCodeHelper.h',
'bindings/core/v8/V8DOMConfiguration.h',
'bindings/core/v8/V8ObjectConstructor.h',
'core/dom/Document.h',
Expand Down
6 changes: 4 additions & 2 deletions third_party/WebKit/Source/bindings/templates/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ v8::Local<v8::FunctionTemplate> {{v8_class}}Constructor::domTemplate(v8::Isolate
{% if constructor_overloads %}
static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
{
ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interface_name}}", info.Holder(), info.GetIsolate());
ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionContext, "{{interface_name}}");
{# 2. Initialize argcount to be min(maxarg, n). #}
switch (std::min({{constructor_overloads.maxarg}}, info.Length())) {
{# 3. Remove from S all entries whose type list is not of length argcount. #}
Expand All @@ -545,7 +545,7 @@ static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
{# Report full list of valid arities if gaps and above minimum #}
{% if constructor_overloads.valid_arities %}
if (info.Length() >= {{constructor_overloads.length}}) {
setArityTypeError(exceptionState, "{{constructor_overloads.valid_arities}}", info.Length());
exceptionState.throwTypeError(ExceptionMessages::invalidArity("{{constructor_overloads.valid_arities}}", info.Length()));
return;
}
{% endif %}
Expand All @@ -560,6 +560,7 @@ static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
{% endif %}
{% endblock %}


{##############################################################################}
{% block visit_dom_wrapper %}
{% if has_visit_dom_wrapper %}
Expand Down Expand Up @@ -745,6 +746,7 @@ v8::Local<v8::FunctionTemplate> {{v8_class}}::domTemplateForNamedPropertiesObjec
{% endif %}
{% endblock %}


{##############################################################################}
{% block has_instance %}
{% if not is_array_buffer_or_view %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ bool securityCheck(v8::Local<v8::Context> accessingContext, v8::Local<v8::Object
{{generate_method(method, world_suffix)}}
{% endif %}
{% if method.is_post_message and not is_partial %}
{{generate_post_message_impl()}}
{{generate_post_message_impl(method)}}
{% endif %}
{% if method.overloads and method.overloads.visible %}
{% if method.overloads.runtime_determined_lengths %}
Expand Down
16 changes: 8 additions & 8 deletions third_party/WebKit/Source/bindings/templates/methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ return;
{######################################}
{% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %}
{% if method.has_exception_state %}
setMinimumArityTypeError(exceptionState, {{number_of_required_arguments}}, info.Length());
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{method.number_of_required_arguments}}, info.Length()));
{{propagate_error_with_exception_state(method)}}
{%- elif method.idl_type == 'Promise' %}
v8SetReturnValue(info, ScriptPromise::rejectRaw(ScriptState::current(info.GetIsolate()), {{create_minimum_arity_type_error_without_exception_state(method, number_of_required_arguments)}}));
Expand All @@ -338,9 +338,9 @@ return;
{######################################}
{% macro create_minimum_arity_type_error_without_exception_state(method, number_of_required_arguments) %}
{% if method.is_constructor %}
createMinimumArityTypeErrorForConstructor(info.GetIsolate(), "{{interface_name}}", {{number_of_required_arguments}}, info.Length())
V8ThrowException::createTypeError(info.GetIsolate(), ExceptionMessages::failedToConstruct("{{interface_name}}", ExceptionMessages::notEnoughArguments({{number_of_required_arguments}}, info.Length())))
{%- else %}
createMinimumArityTypeErrorForMethod(info.GetIsolate(), "{{method.name}}", "{{interface_name}}", {{number_of_required_arguments}}, info.Length())
V8ThrowException::createTypeError(info.GetIsolate(), ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", ExceptionMessages::notEnoughArguments({{number_of_required_arguments}}, info.Length())))
{%- endif %}
{%- endmacro %}

Expand Down Expand Up @@ -426,7 +426,7 @@ static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI
{# Report full list of valid arities if gaps and above minimum #}
{% if overloads.valid_arities %}
if (info.Length() >= {{overloads.length}}) {
setArityTypeError(exceptionState, "{{overloads.valid_arities}}", info.Length());
exceptionState.throwTypeError(ExceptionMessages::invalidArity("{{overloads.valid_arities}}", info.Length()));
{{propagate_error_with_exception_state(overloads) | indent(12)}}
}
{% endif %}
Expand All @@ -453,12 +453,12 @@ static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI


{##############################################################################}
{% macro generate_post_message_impl() %}
{% macro generate_post_message_impl(method) %}
static void postMessageImpl(const char* interfaceName, {{cpp_class}}* instance, const v8::FunctionCallbackInfo<v8::Value>& info)
{
ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage", interfaceName, info.Holder(), info.GetIsolate());
if (UNLIKELY(info.Length() < 1)) {
setMinimumArityTypeError(exceptionState, 1, info.Length());
ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionContext, interfaceName, "postMessage");
if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) {
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{method.number_of_required_arguments}}, info.Length()));
return;
}
Transferables transferables;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "V8ArrayBuffer.h"

#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/GeneratedCodeHelper.h"
#include "bindings/core/v8/V8ArrayBuffer.h"
#include "bindings/core/v8/V8DOMConfiguration.h"
#include "bindings/core/v8/V8ObjectConstructor.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#ifndef V8ArrayBuffer_h
#define V8ArrayBuffer_h

#include "bindings/core/v8/GeneratedCodeHelper.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "bindings/core/v8/ToV8.h"
#include "bindings/core/v8/V8Binding.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "V8ArrayBufferView.h"

#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/GeneratedCodeHelper.h"
#include "bindings/core/v8/V8ArrayBuffer.h"
#include "bindings/core/v8/V8DOMConfiguration.h"
#include "bindings/core/v8/V8DataView.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#ifndef V8ArrayBufferView_h
#define V8ArrayBufferView_h

#include "bindings/core/v8/GeneratedCodeHelper.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "bindings/core/v8/ToV8.h"
#include "bindings/core/v8/V8Binding.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "V8DataView.h"

#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/GeneratedCodeHelper.h"
#include "bindings/core/v8/V8ArrayBuffer.h"
#include "bindings/core/v8/V8DOMConfiguration.h"
#include "bindings/core/v8/V8ObjectConstructor.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#ifndef V8DataView_h
#define V8DataView_h

#include "bindings/core/v8/GeneratedCodeHelper.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "bindings/core/v8/ToV8.h"
#include "bindings/core/v8/V8ArrayBufferView.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "V8SVGTestInterface.h"

#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/GeneratedCodeHelper.h"
#include "bindings/core/v8/V8DOMConfiguration.h"
#include "bindings/core/v8/V8ObjectConstructor.h"
#include "core/SVGNames.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#ifndef V8SVGTestInterface_h
#define V8SVGTestInterface_h

#include "bindings/core/v8/GeneratedCodeHelper.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "bindings/core/v8/ToV8.h"
#include "bindings/core/v8/V8Binding.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "V8TestException.h"

#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/GeneratedCodeHelper.h"
#include "bindings/core/v8/V8DOMConfiguration.h"
#include "bindings/core/v8/V8ObjectConstructor.h"
#include "core/dom/Document.h"
Expand Down Expand Up @@ -86,7 +87,7 @@ static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
{
ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestException", info.Holder(), info.GetIsolate());
if (UNLIKELY(info.Length() < 1)) {
setMinimumArityTypeError(exceptionState, 1, info.Length());
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
return;
}
unsigned argument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#ifndef V8TestException_h
#define V8TestException_h

#include "bindings/core/v8/GeneratedCodeHelper.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "bindings/core/v8/ToV8.h"
#include "bindings/core/v8/V8Binding.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "V8TestIntegerIndexed.h"

#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/GeneratedCodeHelper.h"
#include "bindings/core/v8/V8DOMConfiguration.h"
#include "bindings/core/v8/V8Document.h"
#include "bindings/core/v8/V8Node.h"
Expand Down Expand Up @@ -80,7 +81,7 @@ void lengthAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>& in
static void voidMethodDocumentMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
{
if (UNLIKELY(info.Length() < 1)) {
V8ThrowException::throwException(info.GetIsolate(), createMinimumArityTypeErrorForMethod(info.GetIsolate(), "voidMethodDocument", "TestIntegerIndexed", 1, info.Length()));
V8ThrowException::throwException(info.GetIsolate(), V8ThrowException::createTypeError(info.GetIsolate(), ExceptionMessages::failedToExecute("voidMethodDocument", "TestIntegerIndexed", ExceptionMessages::notEnoughArguments(1, info.Length()))));
return;
}
TestIntegerIndexed* impl = V8TestIntegerIndexed::toImpl(info.Holder());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#ifndef V8TestIntegerIndexed_h
#define V8TestIntegerIndexed_h

#include "bindings/core/v8/GeneratedCodeHelper.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "bindings/core/v8/ToV8.h"
#include "bindings/core/v8/V8Binding.h"
Expand Down
Loading

0 comments on commit c42a74b

Please sign in to comment.