1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25 #include "config.h"
26
27 #if ENABLE(WEB_AUDIO)
28
29 #include "V8AudioNode.h"
30
31 #include "AudioNode.h"
32 #include "ExceptionCode.h"
33 #include "NotImplemented.h"
34 #include "V8Binding.h"
35 #include "V8Proxy.h"
36
37 namespace WebCore {
38
connectCallback(const v8::Arguments & args)39 v8::Handle<v8::Value> V8AudioNode::connectCallback(const v8::Arguments& args)
40 {
41 if (args.Length() < 1)
42 return throwError("Not enough arguments", V8Proxy::SyntaxError);
43
44 AudioNode* destinationNode = toNative(args[0]->ToObject());
45 if (!destinationNode)
46 return throwError("Invalid destination node", V8Proxy::SyntaxError);
47
48 unsigned output = 0;
49 unsigned input = 0;
50 bool ok = false;
51 if (args.Length() > 1) {
52 output = toInt32(args[1], ok);
53 if (!ok)
54 return throwError("Invalid index parameters", V8Proxy::SyntaxError);
55 }
56
57 if (args.Length() > 2) {
58 input = toInt32(args[2], ok);
59 if (!ok)
60 return throwError("Invalid index parameters", V8Proxy::SyntaxError);
61 }
62
63 AudioNode* audioNode = toNative(args.Holder());
64 bool success = audioNode->connect(destinationNode, output, input);
65 if (!success)
66 return throwError("Invalid index parameter", V8Proxy::SyntaxError);
67
68 return v8::Undefined();
69 }
70
disconnectCallback(const v8::Arguments & args)71 v8::Handle<v8::Value> V8AudioNode::disconnectCallback(const v8::Arguments& args)
72 {
73 unsigned output = 0;
74 bool ok = false;
75 if (args.Length() > 0) {
76 output = toInt32(args[0], ok);
77 if (!ok)
78 return throwError("Invalid index parameters", V8Proxy::SyntaxError);
79 }
80
81 AudioNode* audioNode = toNative(args.Holder());
82 bool success = audioNode->disconnect(output);
83 if (!success)
84 return throwError("Invalid index parameter", V8Proxy::SyntaxError);
85
86 return v8::Undefined();
87 }
88
89 } // namespace WebCore
90
91 #endif // ENABLE(WEB_AUDIO)
92