forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bindings: Add enum support for callback functions
- Update IdlTypeBase.callback_cpp_type to handle enums. (This should be removed though) - Generated call() function won't accept invalid enum values. When an invalid enum is passed, it will crash. BUG=569301 Change-Id: Ie2b7aa1f314ce70e9f7c2cfec0ca995cc165bdec Reviewed-on: https://chromium-review.googlesource.com/517587 Commit-Queue: Kenichi Ishibashi <bashi@chromium.org> Reviewed-by: Kentaro Hara <haraken@chromium.org> Reviewed-by: Hitoshi Yoshida <peria@chromium.org> Reviewed-by: Yuki Shiino <yukishiino@chromium.org> Cr-Commit-Position: refs/heads/master@{#475532}
- Loading branch information
Showing
20 changed files
with
258 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
third_party/WebKit/Source/bindings/tests/results/core/VoidCallbackFunctionEnumArg.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// This file has been auto-generated by code_generator_v8.py. | ||
// DO NOT MODIFY! | ||
|
||
// This file has been generated from the Jinja2 template in | ||
// third_party/WebKit/Source/bindings/templates/callback_function.cpp.tmpl | ||
|
||
// clang-format off | ||
|
||
#include "VoidCallbackFunctionEnumArg.h" | ||
|
||
#include "bindings/core/v8/ExceptionState.h" | ||
#include "bindings/core/v8/IDLTypes.h" | ||
#include "bindings/core/v8/NativeValueTraitsImpl.h" | ||
#include "bindings/core/v8/ToV8ForCore.h" | ||
#include "bindings/core/v8/V8BindingForCore.h" | ||
#include "core/dom/ExecutionContext.h" | ||
#include "platform/bindings/ScriptState.h" | ||
#include "platform/wtf/Assertions.h" | ||
|
||
namespace blink { | ||
|
||
// static | ||
VoidCallbackFunctionEnumArg* VoidCallbackFunctionEnumArg::Create(ScriptState* scriptState, v8::Local<v8::Value> callback) { | ||
if (IsUndefinedOrNull(callback)) | ||
return nullptr; | ||
return new VoidCallbackFunctionEnumArg(scriptState, v8::Local<v8::Function>::Cast(callback)); | ||
} | ||
|
||
VoidCallbackFunctionEnumArg::VoidCallbackFunctionEnumArg(ScriptState* scriptState, v8::Local<v8::Function> callback) | ||
: script_state_(scriptState), | ||
callback_(scriptState->GetIsolate(), this, callback) { | ||
DCHECK(!callback_.IsEmpty()); | ||
} | ||
|
||
DEFINE_TRACE_WRAPPERS(VoidCallbackFunctionEnumArg) { | ||
visitor->TraceWrappers(callback_.Cast<v8::Value>()); | ||
} | ||
|
||
bool VoidCallbackFunctionEnumArg::call(ScriptWrappable* scriptWrappable, const String& arg) { | ||
if (callback_.IsEmpty()) | ||
return false; | ||
|
||
if (!script_state_->ContextIsValid()) | ||
return false; | ||
|
||
// TODO(bashi): Make sure that using DummyExceptionStateForTesting is OK. | ||
// crbug.com/653769 | ||
DummyExceptionStateForTesting exceptionState; | ||
|
||
const char* valid_arg_values[] = { | ||
"", | ||
"EnumValue1", | ||
"EnumValue2", | ||
"EnumValue3", | ||
}; | ||
if (!IsValidEnum(arg, valid_arg_values, WTF_ARRAY_LENGTH(valid_arg_values), "TestEnum", exceptionState)) { | ||
NOTREACHED(); | ||
return false; | ||
} | ||
|
||
ExecutionContext* context = ExecutionContext::From(script_state_.Get()); | ||
DCHECK(context); | ||
if (context->IsContextSuspended() || context->IsContextDestroyed()) | ||
return false; | ||
|
||
ScriptState::Scope scope(script_state_.Get()); | ||
v8::Isolate* isolate = script_state_->GetIsolate(); | ||
|
||
v8::Local<v8::Value> thisValue = ToV8( | ||
scriptWrappable, | ||
script_state_->GetContext()->Global(), | ||
isolate); | ||
|
||
v8::Local<v8::Value> v8_arg = V8String(script_state_->GetIsolate(), arg); | ||
v8::Local<v8::Value> argv[] = { v8_arg }; | ||
v8::TryCatch exceptionCatcher(isolate); | ||
exceptionCatcher.SetVerbose(true); | ||
|
||
v8::Local<v8::Value> v8ReturnValue; | ||
if (!V8ScriptRunner::CallFunction(callback_.NewLocal(isolate), | ||
context, | ||
thisValue, | ||
1, | ||
argv, | ||
isolate).ToLocal(&v8ReturnValue)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
VoidCallbackFunctionEnumArg* NativeValueTraits<VoidCallbackFunctionEnumArg>::NativeValue(v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionState& exceptionState) { | ||
VoidCallbackFunctionEnumArg* nativeValue = VoidCallbackFunctionEnumArg::Create(ScriptState::Current(isolate), value); | ||
if (!nativeValue) { | ||
exceptionState.ThrowTypeError(ExceptionMessages::FailedToConvertJSValue( | ||
"VoidCallbackFunctionEnumArg")); | ||
} | ||
return nativeValue; | ||
} | ||
|
||
} // namespace blink |
Oops, something went wrong.