Bug 78043

Summary: Make it possible to create JavaScriptAudioNode-based Web Audio nodes
Product: WebKit Reporter: Boris Smus <smus>
Component: Web AudioAssignee: Nobody <webkit-unassigned>
Status: RESOLVED WONTFIX    
Severity: Normal CC: crogers, ericbidelman, rgbbones
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   

Description Boris Smus 2012-02-07 14:45:06 PST
I'm trying to create a custom node based on the JavaScriptAudioNode by extending its prototype with a custom function, and then plugging it into the audio graph. Unfortunately, doing this causes a "SyntaxError: Invalid destination node" error, and the audio graph rejects the custom node.

Here's what I'm doing:

1. I extend the context with a createCustomNode call, as follows:

// Augment the context with a createMeterNode call that returns an augmented
// JavaScriptAudioNode.

function registerCustomWebAudioNode(context, constructorName, classObject) {
  // Get the webkitAudioContext and extend its prototype.
  webkitAudioContext.prototype[constructorName] = function() {
    var customNode = new classObject(this);
    customNode.prototype = context.createJavaScriptNode(2048, 1, 1);
    return customNode;
  }
}

function MeterNode(context) {
  console.log('init');
}

MeterNode.prototype.onClip = function(callback) {
  // ...
};

2. Then, I'm using the custom node as follows:

    // Assuming context, source are initialized earlier.
    meter = context.createMeterNode();
    // Connect source to meter node to destination.
    source.connect(meter);
    meter.connect(context.destination);

3. I get an error: SyntaxError: Invalid destination node

This sounds like something at the JavaScript - C++ bindings layer.
Comment 1 Raymond 2012-04-05 01:03:09 PDT
Interesting, just curious on your implementation. Do you have full source code on how you call registerCustomWebAudioNode and use MeterNode etc.?
Comment 2 Chris Rogers 2013-05-10 17:48:21 PDT
It appears that extending the prototype like this is very hard or impossible to do given the way the JS bindings system works