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) {
|
static v8::Handle<v8::Value> V8New(const v8::Arguments& args) {
|
||||||
if (!args.IsConstructCall())
|
if (!args.IsConstructCall())
|
||||||
return ThrowTypeError("Constructor cannot be called as a function.");
|
return node::FromConstructorTemplate(GetTemplate(), args);
|
||||||
|
|
||||||
// To match Chrome, we allow "new ArrayBuffer()".
|
// To match Chrome, we allow "new ArrayBuffer()".
|
||||||
// if (args.Length() != 1)
|
// if (args.Length() != 1)
|
||||||
@ -241,7 +241,7 @@ class TypedArray {
|
|||||||
private:
|
private:
|
||||||
static v8::Handle<v8::Value> V8New(const v8::Arguments& args) {
|
static v8::Handle<v8::Value> V8New(const v8::Arguments& args) {
|
||||||
if (!args.IsConstructCall())
|
if (!args.IsConstructCall())
|
||||||
return ThrowTypeError("Constructor cannot be called as a function.");
|
return node::FromConstructorTemplate(GetTemplate(), args);
|
||||||
|
|
||||||
// To match Chrome, we allow "new Float32Array()".
|
// To match Chrome, we allow "new Float32Array()".
|
||||||
// if (args.Length() != 1)
|
// if (args.Length() != 1)
|
||||||
@ -613,7 +613,7 @@ class DataView {
|
|||||||
private:
|
private:
|
||||||
static v8::Handle<v8::Value> V8New(const v8::Arguments& args) {
|
static v8::Handle<v8::Value> V8New(const v8::Arguments& args) {
|
||||||
if (!args.IsConstructCall())
|
if (!args.IsConstructCall())
|
||||||
return ThrowTypeError("Constructor cannot be called as a function.");
|
return node::FromConstructorTemplate(GetTemplate(), args);
|
||||||
|
|
||||||
if (args.Length() < 1)
|
if (args.Length() < 1)
|
||||||
return ThrowError("Wrong number of arguments.");
|
return ThrowError("Wrong number of arguments.");
|
||||||
|
@ -50,8 +50,14 @@ var assert = require('assert');
|
|||||||
obj = new DataView(obj.buffer || obj);
|
obj = new DataView(obj.buffer || obj);
|
||||||
assert.equal(obj.toString(), '[object DataView]');
|
assert.equal(obj.toString(), '[object DataView]');
|
||||||
assert.equal(Object.prototype.toString.call(obj), '[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 buffer = new ArrayBuffer(16);
|
||||||
var uint8 = new Uint8Array(buffer);
|
var uint8 = new Uint8Array(buffer);
|
||||||
var uint16 = new Uint16Array(buffer);
|
var uint16 = new Uint16Array(buffer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user