| Index: Source/bindings/modules/v8/custom/V8MIDIAccessCustom.cpp
|
| diff --git a/Source/bindings/modules/v8/custom/V8MIDIAccessCustom.cpp b/Source/bindings/modules/v8/custom/V8MIDIAccessCustom.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ed9b9efac9bf535f75922d5ade40d6bed2d9c533
|
| --- /dev/null
|
| +++ b/Source/bindings/modules/v8/custom/V8MIDIAccessCustom.cpp
|
| @@ -0,0 +1,104 @@
|
| +// 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.
|
| +
|
| +#include "config.h"
|
| +#include "bindings/modules/v8/V8MIDIAccess.h"
|
| +
|
| +#include "bindings/core/v8/V8Binding.h"
|
| +#include "bindings/modules/v8/V8MIDIInputMap.h"
|
| +#include "bindings/modules/v8/V8MIDIOutputMap.h"
|
| +#include "modules/webmidi/MIDIInputMap.h"
|
| +#include "modules/webmidi/MIDIOutputMap.h"
|
| +
|
| +// This implementation is needed to keep the old inputs / outputs APIs. Delete
|
| +// it after the new APIs are widely accepted.
|
| +
|
| +namespace blink {
|
| +
|
| +namespace {
|
| +
|
| +#define DEFINE_BOUND_FUNCTION(name) \
|
| +void name(const v8::FunctionCallbackInfo<v8::Value>& info) \
|
| +{ \
|
| + v8::Isolate* isolate = info.GetIsolate(); \
|
| + v8::Local<v8::Object> mapWrapper = info.Data().As<v8::Object>(); \
|
| + v8::Local<v8::Value> functionObject = mapWrapper->Get(v8String(isolate, #name)); \
|
| + if (functionObject.IsEmpty() || !functionObject->IsFunction()) { \
|
| + V8ThrowException::throwTypeError("Cannot call the function", isolate); \
|
| + return; \
|
| + } \
|
| + v8::Local<v8::Function> function = functionObject.As<v8::Function>(); \
|
| + Vector<v8::Local<v8::Value> > args; \
|
| + for (int i = 0; i < info.Length(); ++i) \
|
| + args.append(info[i]); \
|
| + info.GetReturnValue().Set(function->Call(mapWrapper, info.Length(), info.Length() > 0 ? &args[0] : 0)); \
|
| +}
|
| +
|
| +DEFINE_BOUND_FUNCTION(keys)
|
| +DEFINE_BOUND_FUNCTION(entries)
|
| +DEFINE_BOUND_FUNCTION(values)
|
| +DEFINE_BOUND_FUNCTION(get)
|
| +DEFINE_BOUND_FUNCTION(has)
|
| +
|
| +void size(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
|
| +{
|
| + v8::Isolate* isolate = info.GetIsolate();
|
| + v8::Local<v8::Object> mapWrapper = info.Data().As<v8::Object>();
|
| + info.GetReturnValue().Set(mapWrapper->Get(v8String(isolate, "size")));
|
| +}
|
| +
|
| +void installMapMethods(v8::Isolate* isolate, v8::Handle<v8::Object> wrapper, v8::Handle<v8::Object> mapWrapper)
|
| +{
|
| + wrapper->SetAccessor(v8String(isolate, "size"), size, 0, mapWrapper);
|
| + wrapper->Set(v8String(isolate, "keys"), v8::Function::New(isolate, keys, mapWrapper));
|
| + wrapper->Set(v8String(isolate, "entries"), v8::Function::New(isolate, entries, mapWrapper));
|
| + wrapper->Set(v8String(isolate, "values"), v8::Function::New(isolate, values, mapWrapper));
|
| + wrapper->Set(v8String(isolate, "get"), v8::Function::New(isolate, get, mapWrapper));
|
| + wrapper->Set(v8String(isolate, "has"), v8::Function::New(isolate, has, mapWrapper));
|
| + wrapper->Set(v8::Symbol::GetIterator(isolate), v8::Function::New(isolate, values, mapWrapper));
|
| +}
|
| +
|
| +void inputsArray(const v8::FunctionCallbackInfo<v8::Value>& info)
|
| +{
|
| + MIDIAccess* impl = V8MIDIAccess::toNative(info.Data().As<v8::Object>());
|
| + v8SetReturnValue(info, v8Array(impl->inputsAsVector(), info.Holder(), info.GetIsolate()));
|
| +}
|
| +
|
| +void outputsArray(const v8::FunctionCallbackInfo<v8::Value>& info)
|
| +{
|
| + MIDIAccess* impl = V8MIDIAccess::toNative(info.Data().As<v8::Object>());
|
| + v8SetReturnValue(info, v8Array(impl->outputsAsVector(), info.Holder(), info.GetIsolate()));
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +void V8MIDIAccess::inputsAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>& info)
|
| +{
|
| + v8::Handle<v8::Object> holder = info.Holder();
|
| + MIDIAccess* impl = V8MIDIAccess::toNative(holder);
|
| + RawPtr<MIDIInputMap> cppValue(impl->inputs());
|
| + v8::Handle<v8::Value> wrapper = toV8(cppValue.get(), holder, info.GetIsolate());
|
| + if (!wrapper.IsEmpty() && wrapper->IsObject()) {
|
| + V8HiddenValue::setHiddenValue(info.GetIsolate(), holder, v8AtomicString(info.GetIsolate(), "inputs"), wrapper);
|
| + v8::Local<v8::Function> function = v8::Function::New(info.GetIsolate(), inputsArray, holder);
|
| + installMapMethods(info.GetIsolate(), function, wrapper.As<v8::Object>());
|
| + v8SetReturnValue(info, function);
|
| + }
|
| +}
|
| +
|
| +void V8MIDIAccess::outputsAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>& info)
|
| +{
|
| + v8::Handle<v8::Object> holder = info.Holder();
|
| + MIDIAccess* impl = V8MIDIAccess::toNative(holder);
|
| + RawPtr<MIDIOutputMap> cppValue(impl->outputs());
|
| + v8::Handle<v8::Value> wrapper = toV8(cppValue.get(), holder, info.GetIsolate());
|
| + if (!wrapper.IsEmpty() && wrapper->IsObject()) {
|
| + V8HiddenValue::setHiddenValue(info.GetIsolate(), holder, v8AtomicString(info.GetIsolate(), "outputs"), wrapper);
|
| + v8::Local<v8::Function> function = v8::Function::New(info.GetIsolate(), outputsArray, holder);
|
| + installMapMethods(info.GetIsolate(), function, wrapper.As<v8::Object>());
|
| + v8SetReturnValue(info, function);
|
| + }
|
| +}
|
| +
|
| +} // namespace blink
|
|
|