typed arrays: make call-as-function work for ctors
Turn call-as-function calls into constructor calls. Makes the following snippet work: var buf = ArrayBuffer(32); // no 'new' but does the right thing
This commit is contained in:
parent
aff8d9e716
commit
ed3d553d82
@ -88,7 +88,7 @@ class ArrayBuffer {
|
||||
|
||||
static v8::Handle<v8::Value> V8New(const v8::Arguments& args) {
|
||||
if (!args.IsConstructCall())
|
||||
return ThrowTypeError("Constructor cannot be called as a function.");
|
||||
return node::FromConstructorTemplate(GetTemplate(), args);
|
||||
|
||||
// To match Chrome, we allow "new ArrayBuffer()".
|
||||
// if (args.Length() != 1)
|
||||
@ -241,7 +241,7 @@ class TypedArray {
|
||||
private:
|
||||
static v8::Handle<v8::Value> V8New(const v8::Arguments& args) {
|
||||
if (!args.IsConstructCall())
|
||||
return ThrowTypeError("Constructor cannot be called as a function.");
|
||||
return node::FromConstructorTemplate(GetTemplate(), args);
|
||||
|
||||
// To match Chrome, we allow "new Float32Array()".
|
||||
// if (args.Length() != 1)
|
||||
@ -613,7 +613,7 @@ class DataView {
|
||||
private:
|
||||
static v8::Handle<v8::Value> V8New(const v8::Arguments& args) {
|
||||
if (!args.IsConstructCall())
|
||||
return ThrowTypeError("Constructor cannot be called as a function.");
|
||||
return node::FromConstructorTemplate(GetTemplate(), args);
|
||||
|
||||
if (args.Length() < 1)
|
||||
return ThrowError("Wrong number of arguments.");
|
||||
|
@ -50,8 +50,14 @@ var assert = require('assert');
|
||||
obj = new DataView(obj.buffer || obj);
|
||||
assert.equal(obj.toString(), '[object DataView]');
|
||||
assert.equal(Object.prototype.toString.call(obj), '[object DataView]');
|
||||
|
||||
// Calling constructor as function should work.
|
||||
clazz(32);
|
||||
});
|
||||
|
||||
// Calling constructor as function should work.
|
||||
DataView(ArrayBuffer(32));
|
||||
|
||||
var buffer = new ArrayBuffer(16);
|
||||
var uint8 = new Uint8Array(buffer);
|
||||
var uint16 = new Uint16Array(buffer);
|
||||
|
Loading…
x
Reference in New Issue
Block a user