v8::HandleScope scope;
ft_cache = v8::Persistent<v8::FunctionTemplate>::New(
v8::FunctionTemplate::New(&TypedArray<TBytes, TEAType>::V8New));
+ ft_cache->SetClassName(v8::String::New(TypeName()));
v8::Local<v8::ObjectTemplate> instance = ft_cache->InstanceTemplate();
instance->SetInternalFieldCount(0);
return TypedArray<TBytes, TEAType>::GetTemplate()->
GetFunction()->NewInstance(3, argv);
}
+
+ static const char* TypeName() {
+ switch (TEAType) {
+ case v8::kExternalByteArray: return "Int8Array";
+ case v8::kExternalUnsignedByteArray: return "Uint8Array";
+ case v8::kExternalShortArray: return "Int16Array";
+ case v8::kExternalUnsignedShortArray: return "Uint16Array";
+ case v8::kExternalIntArray: return "Int32Array";
+ case v8::kExternalUnsignedIntArray: return "Uint32Array";
+ case v8::kExternalFloatArray: return "Float32Array";
+ case v8::kExternalDoubleArray: return "Float64Array";
+ }
+ abort();
+ }
};
class Int8Array : public TypedArray<1, v8::kExternalByteArray> { };
--- /dev/null
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('../common');
+var assert = require('assert');
+
+// TODO: merge with test-typed-arrays.js some time in the future.
+// That file only exists in master right now.
+[
+ 'ArrayBuffer',
+ 'Int8Array',
+ 'Uint8Array',
+ 'Int16Array',
+ 'Uint16Array',
+ 'Int32Array',
+ 'Uint32Array',
+ 'Float32Array',
+ 'Float64Array'
+].forEach(function(name) {
+ var expected = '[object ' + name + ']';
+ var clazz = global[name];
+ var obj = new clazz(1);
+
+ assert.equal(obj.toString(), expected);
+ assert.equal(Object.prototype.toString.call(obj), expected);
+
+ obj = new DataView(obj);
+ assert.equal(obj.toString(), '[object DataView]');
+ assert.equal(Object.prototype.toString.call(obj), '[object DataView]');
+});