/*global Module*/
/*global _malloc, _free, _memcpy*/
/*global FUNCTION_TABLE, HEAP32, HEAPU8*/
/*global Pointer_stringify*/
/*global __emval_register, _emval_handle_array, __emval_decref*/
/*global ___getDynamicPointerType: false*/
/*global ___typeName:false*/
/*global ___staticPointerCast: false*/
var BindingError = Module.BindingError = extendError(Error, 'BindingError');
var CastError = Module.CastError = extendError(Error, 'CastError');
function throwBindingError(value) {
throw new BindingError(value);
}
function exposePublicSymbol(name, value) {
if (Module.hasOwnProperty(name)) {
throwBindingError("Cannot register public name '" + name + "' twice");
}
Module[name] = value;
}
// from https://github.com/imvu/imvujs/blob/master/src/error.js
function extendError(baseErrorType, errorName) {
var errorClass = createNamedFunction(errorName, function(message) {
this.name = errorName;
this.message = message;
var stack = (new Error(message)).stack;
if (stack !== undefined) {
this.stack = this.toString() + '\n' +
stack.replace(/^Error(:[^\n]*)?\n/, '');
}
});
errorClass.prototype = Object.create(baseErrorType.prototype);
errorClass.prototype.constructor = errorClass;
errorClass.prototype.toString = function() {
if (this.message === undefined) {
return this.name;
} else {
return this.name + ': ' + this.message;
}
};
return errorClass;
}
// from https://github.com/imvu/imvujs/blob/master/src/function.js
function createNamedFunction(name, body) {
/*jshint evil:true*/
return new Function(
"body",
"return function " + name + "() {\n" +
" return body.apply(this, arguments);\n" +
"};\n"
)(body);
}
function _embind_repr(v) {
var t = typeof v;
if (t === 'object' || t === 'array' || t === 'function') {
return v.toString();
} else {
return '' + v;
}
}
var typeRegistry = {};
var deferredRegistrations = [];
function requestDeferredRegistration(registrationFunction) {
deferredRegistrations.push(registrationFunction);
}
function performDeferredRegistrations(){
while(deferredRegistrations.length > 0) {
var registrationFunction = deferredRegistrations.shift();
registrationFunction();
}
}
function createInheritedFunctionOrProperty(name, type, nameInBaseClass, baseClassType) {
function upcastingWrapper(method) {
return function() {
var baseClassPtr = ___staticPointerCast(this.$$.ptr, type.rawType, baseClassType.rawType);
if (baseClassPtr === this.$$.ptr) {
return method.apply(this, arguments);
} else {
var handle = this.clone();
try {
handle.$$.ptr = baseClassPtr;
return method.apply(handle, arguments);
} finally {
handle.delete();
}
}
};
}
var baseClassPrototype = baseClassType.Handle.prototype;
if (baseClassPrototype.constructor.memberType[nameInBaseClass] === 'field') {
var baseClassDescriptor = Object.getOwnPropertyDescriptor(baseClassPrototype, nameInBaseClass);
Object.defineProperty(type.Handle.prototype, name, {
enumerable: true,
get: upcastingWrapper(baseClassDescriptor.get),
set: upcastingWrapper(baseClassDescriptor.set)
});
type.Handle.memberType[name] = 'field';
} else if (baseClassPrototype.c