Chromium Code Reviews

Side by Side Diff: Source/bindings/modules/v8/custom/V8MIDIAccessCustom.cpp

Issue 518633003: [ABANDONED] [WebMIDI] Support the legacy MIDIAccess port API. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@webmidi-input-map
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "bindings/modules/v8/V8MIDIAccess.h"
7
8 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/modules/v8/V8MIDIInputMap.h"
10 #include "bindings/modules/v8/V8MIDIOutputMap.h"
11 #include "modules/webmidi/MIDIInputMap.h"
12 #include "modules/webmidi/MIDIOutputMap.h"
13
14 // This implementation is needed to keep the old inputs / outputs APIs. Delete
15 // it after the new APIs are widely accepted.
16
17 namespace blink {
18
19 namespace {
20
21 #define DEFINE_BOUND_FUNCTION(name) \
22 void name(const v8::FunctionCallbackInfo<v8::Value>& info) \
23 { \
24 v8::Isolate* isolate = info.GetIsolate(); \
25 v8::Local<v8::Object> mapWrapper = info.Data().As<v8::Object>(); \
26 v8::Local<v8::Value> functionObject = mapWrapper->Get(v8String(isolate, #nam e)); \
27 if (functionObject.IsEmpty() || !functionObject->IsFunction()) { \
28 V8ThrowException::throwTypeError("Cannot call the function", isolate); \
29 return; \
30 } \
31 v8::Local<v8::Function> function = functionObject.As<v8::Function>(); \
32 Vector<v8::Local<v8::Value> > args; \
33 for (int i = 0; i < info.Length(); ++i) \
34 args.append(info[i]); \
35 info.GetReturnValue().Set(function->Call(mapWrapper, info.Length(), info.Len gth() > 0 ? &args[0] : 0)); \
36 }
37
38 DEFINE_BOUND_FUNCTION(keys)
39 DEFINE_BOUND_FUNCTION(entries)
40 DEFINE_BOUND_FUNCTION(values)
41 DEFINE_BOUND_FUNCTION(get)
42 DEFINE_BOUND_FUNCTION(has)
43
44 void size(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info )
45 {
46 v8::Isolate* isolate = info.GetIsolate();
47 v8::Local<v8::Object> mapWrapper = info.Data().As<v8::Object>();
48 info.GetReturnValue().Set(mapWrapper->Get(v8String(isolate, "size")));
49 }
50
51 void installMapMethods(v8::Isolate* isolate, v8::Handle<v8::Object> wrapper, v8: :Handle<v8::Object> mapWrapper)
52 {
53 wrapper->SetAccessor(v8String(isolate, "size"), size, 0, mapWrapper);
54 wrapper->Set(v8String(isolate, "keys"), v8::Function::New(isolate, keys, map Wrapper));
55 wrapper->Set(v8String(isolate, "entries"), v8::Function::New(isolate, entrie s, mapWrapper));
56 wrapper->Set(v8String(isolate, "values"), v8::Function::New(isolate, values, mapWrapper));
57 wrapper->Set(v8String(isolate, "get"), v8::Function::New(isolate, get, mapWr apper));
58 wrapper->Set(v8String(isolate, "has"), v8::Function::New(isolate, has, mapWr apper));
59 wrapper->Set(v8::Symbol::GetIterator(isolate), v8::Function::New(isolate, va lues, mapWrapper));
60 }
61
62 void inputsArray(const v8::FunctionCallbackInfo<v8::Value>& info)
63 {
64 MIDIAccess* impl = V8MIDIAccess::toNative(info.Data().As<v8::Object>());
65 v8SetReturnValue(info, v8Array(impl->inputsAsVector(), info.Holder(), info.G etIsolate()));
66 }
67
68 void outputsArray(const v8::FunctionCallbackInfo<v8::Value>& info)
69 {
70 MIDIAccess* impl = V8MIDIAccess::toNative(info.Data().As<v8::Object>());
71 v8SetReturnValue(info, v8Array(impl->outputsAsVector(), info.Holder(), info. GetIsolate()));
72 }
73
74 } // namespace
75
76 void V8MIDIAccess::inputsAttributeGetterCustom(const v8::PropertyCallbackInfo<v8 ::Value>& info)
77 {
78 v8::Handle<v8::Object> holder = info.Holder();
79 MIDIAccess* impl = V8MIDIAccess::toNative(holder);
80 RawPtr<MIDIInputMap> cppValue(impl->inputs());
81 v8::Handle<v8::Value> wrapper = toV8(cppValue.get(), holder, info.GetIsolate ());
82 if (!wrapper.IsEmpty() && wrapper->IsObject()) {
83 V8HiddenValue::setHiddenValue(info.GetIsolate(), holder, v8AtomicString( info.GetIsolate(), "inputs"), wrapper);
84 v8::Local<v8::Function> function = v8::Function::New(info.GetIsolate(), inputsArray, holder);
85 installMapMethods(info.GetIsolate(), function, wrapper.As<v8::Object>()) ;
86 v8SetReturnValue(info, function);
87 }
88 }
89
90 void V8MIDIAccess::outputsAttributeGetterCustom(const v8::PropertyCallbackInfo<v 8::Value>& info)
91 {
92 v8::Handle<v8::Object> holder = info.Holder();
93 MIDIAccess* impl = V8MIDIAccess::toNative(holder);
94 RawPtr<MIDIOutputMap> cppValue(impl->outputs());
95 v8::Handle<v8::Value> wrapper = toV8(cppValue.get(), holder, info.GetIsolate ());
96 if (!wrapper.IsEmpty() && wrapper->IsObject()) {
97 V8HiddenValue::setHiddenValue(info.GetIsolate(), holder, v8AtomicString( info.GetIsolate(), "outputs"), wrapper);
98 v8::Local<v8::Function> function = v8::Function::New(info.GetIsolate(), outputsArray, holder);
99 installMapMethods(info.GetIsolate(), function, wrapper.As<v8::Object>()) ;
100 v8SetReturnValue(info, function);
101 }
102 }
103
104 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/webmidi/legacy-ports-expected.txt ('k') | Source/bindings/modules/v8/custom/custom.gypi » ('j') | no next file with comments »

Powered by Google App Engine