Bug 914220 - Move TypedObject global names into a TypedObject module r=waldo

This commit is contained in:
Nicholas D. Matsakis 2013-09-09 11:52:11 -04:00
parent ebb52400f3
commit 271da5b9d4
35 changed files with 688 additions and 573 deletions

View File

@ -28,11 +28,9 @@ var ecmaGlobals =
[
"Array",
"ArrayBuffer",
{name: "ArrayType", nightly: true},
"Boolean",
"DataView",
"Date",
{name: "Data", nightly: true},
"Error",
"EvalError",
"Float32Array",
@ -59,9 +57,8 @@ var ecmaGlobals =
"Set",
"StopIteration",
"String",
{name: "StructType", nightly: true},
"SyntaxError",
{name: "Type", nightly: true},
{name: "TypedObject", nightly: true},
"TypeError",
"Uint16Array",
"Uint32Array",

View File

@ -560,7 +560,7 @@ struct JSClass {
// with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS was
// previously allowed, but is now an ES5 violation and thus unsupported.
//
#define JSCLASS_GLOBAL_SLOT_COUNT (3 + JSProto_LIMIT * 3 + 26)
#define JSCLASS_GLOBAL_SLOT_COUNT (3 + JSProto_LIMIT * 3 + 27)
#define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n) \
(JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + (n)))
#define JSCLASS_GLOBAL_FLAGS \

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,13 @@
namespace js {
/*
* This object exists in order to encapsulate the typed object types
* somewhat, rather than sticking them all into the global object.
* Eventually it will go away and become a module.
*/
extern const Class TypedObjectClass;
// Slots common to all type descriptors:
enum TypeCommonSlots {
// Canonical type representation of this type (see TypeRepresentation.h).
@ -47,10 +54,6 @@ enum BlockCommonSlots {
BLOCK_RESERVED_SLOTS
};
extern const Class DataClass;
extern const Class TypeClass;
template <ScalarTypeRepresentation::Type type, typename T>
class NumericType
{
@ -62,6 +65,11 @@ class NumericType
static bool call(JSContext *cx, unsigned argc, Value *vp);
};
/*
* These are the classes of the scalar type descriptors, like `uint8`,
* `uint16` etc. Each of these classes has exactly one instance that
* is pre-created.
*/
extern const Class NumericTypeClasses[ScalarTypeRepresentation::TYPE_MAX];
/*
@ -73,12 +81,26 @@ class ArrayType : public JSObject
public:
static const Class class_;
// Properties and methods to be installed on ArrayType.prototype,
// and hence inherited by all array type objects:
static const JSPropertySpec typeObjectProperties[];
static const JSFunctionSpec typeObjectMethods[];
// Properties and methods to be installed on ArrayType.prototype.prototype,
// and hence inherited by all array *typed* objects:
static const JSPropertySpec typedObjectProperties[];
static const JSFunctionSpec typedObjectMethods[];
// This is the function that gets called when the user
// does `new ArrayType(elem)`. It produces an array type object.
static bool construct(JSContext *cx, unsigned argc, Value *vp);
static JSObject *create(JSContext *cx, HandleObject arrayTypeGlobal,
HandleObject elementType, size_t length);
static bool construct(JSContext *cx, unsigned int argc, jsval *vp);
static bool repeat(JSContext *cx, unsigned int argc, jsval *vp);
static bool repeat(JSContext *cx, unsigned argc, Value *vp);
static bool subarray(JSContext *cx, unsigned argc, Value *vp);
static bool toSource(JSContext *cx, unsigned int argc, jsval *vp);
static bool toSource(JSContext *cx, unsigned argc, Value *vp);
static JSObject *elementType(JSContext *cx, HandleObject obj);
};
@ -101,13 +123,25 @@ class StructType : public JSObject
public:
static const Class class_;
static bool toSource(JSContext *cx, unsigned int argc, jsval *vp);
// Properties and methods to be installed on StructType.prototype,
// and hence inherited by all struct type objects:
static const JSPropertySpec typeObjectProperties[];
static const JSFunctionSpec typeObjectMethods[];
// Properties and methods to be installed on StructType.prototype.prototype,
// and hence inherited by all struct *typed* objects:
static const JSPropertySpec typedObjectProperties[];
static const JSFunctionSpec typedObjectMethods[];
// This is the function that gets called when the user
// does `new StructType(...)`. It produces a struct type object.
static bool construct(JSContext *cx, unsigned argc, Value *vp);
static bool toSource(JSContext *cx, unsigned argc, Value *vp);
static bool convertAndCopyTo(JSContext *cx,
StructTypeRepresentation *typeRepr,
HandleValue from, uint8_t *mem);
static bool construct(JSContext *cx, unsigned int argc, jsval *vp);
};
/* Binary data objects and handles */
@ -213,7 +247,7 @@ class BinaryBlock
HandleObject owner, size_t offset);
// user-accessible constructor (`new TypeDescriptor(...)`)
static bool construct(JSContext *cx, unsigned int argc, jsval *vp);
static bool construct(JSContext *cx, unsigned argc, Value *vp);
};

View File

@ -1,8 +1,10 @@
if (!this.hasOwnProperty("Type"))
quit();
// |jit-test| error:RangeError
if (!this.hasOwnProperty("TypedObject"))
throw new RangeError();
function eval() {
yield(undefined)
}
new(StructType)
(eval())
new TypedObject.StructType();
eval();

View File

@ -1,8 +1,8 @@
// |jit-test| error:Error
if (!this.hasOwnProperty("Type"))
if (!this.hasOwnProperty("TypedObject"))
throw new Error("type too large");
var AA = new ArrayType(new ArrayType(uint8, (2147483647)), 5);
var AA = new TypedObject.ArrayType(new ArrayType(TypedObject.uint8, 2147483647), 5);
var aa = new AA();
var aa0 = aa[0];

View File

@ -1,13 +1,13 @@
// |jit-test| error:Error
if (!this.hasOwnProperty("Type"))
if (!this.hasOwnProperty("TypedObject"))
throw new Error("type too large");
var A = new ArrayType(uint8, (2147483647));
var S = new StructType({a: A,
b: A,
c: A,
d: A,
e: A});
var A = new TypedObject.ArrayType(TypedObject.uint8, 2147483647);
var S = new TypedObject.StructType({a: A,
b: A,
c: A,
d: A,
e: A});
var aa = new S();
var aa0 = aa.a;

View File

@ -1,4 +1,4 @@
if (!this.hasOwnProperty("Type"))
if (!this.hasOwnProperty("TypedObject"))
quit();
new StructType([])
new TypedObject.StructType([]);

View File

@ -1,7 +1,7 @@
// |jit-test| error:RangeError;
if (!this.hasOwnProperty("Type"))
if (!this.hasOwnProperty("TypedObject"))
throw new RangeError();
this.__proto__ = Proxy.create({});
new StructType;
new TypedObject.StructType;

View File

@ -1,9 +1,9 @@
// |jit-test| error:Error;
if (!this.hasOwnProperty("Type"))
if (!this.hasOwnProperty("TypedObject"))
throw new Error();
var A = new ArrayType(uint8, 10);
var A = new TypedObject.ArrayType(TypedObject.uint8, 10);
var a = new A();
a.forEach(function(val, i) {
assertEq(arguments[5], a);

View File

@ -1,6 +1,8 @@
if (!this.hasOwnProperty("Type"))
if (!this.hasOwnProperty("TypedObject"))
quit();
var Color = new StructType({r: uint8, g: uint8, b: uint8});
var Color = new TypedObject.StructType({r: TypedObject.uint8,
g: TypedObject.uint8,
b: TypedObject.uint8});
var white2 = new Color({r: 255, toString: null, b: 253});

View File

@ -1,6 +1,6 @@
// |jit-test| error:TypeError
if (!this.hasOwnProperty("Type"))
if (!this.hasOwnProperty("TypedObject"))
throw new TypeError();
new StructType(RegExp);
new TypedObject.StructType(RegExp);

View File

@ -1,4 +1,4 @@
if (!this.hasOwnProperty("Type"))
if (!this.hasOwnProperty("TypedObject"))
quit();
new StructType(RegExp());
new TypedObject.StructType(RegExp());

View File

@ -1,6 +1,6 @@
// |jit-test| error:Error
if (!this.hasOwnProperty("Type"))
if (!this.hasOwnProperty("TypedObject"))
throw new Error();
new ArrayType(uint8, .0000000009);
new TypedObject.ArrayType(TypedObject.uint8, .0000000009);

View File

@ -1,10 +1,10 @@
// |jit-test| error: TypeError
if (!this.hasOwnProperty("Type"))
if (!this.hasOwnProperty("TypedObject"))
throw new TypeError();
var Vec3 = new ArrayType(float32, 3);
var Sprite = new ArrayType(Vec3, 3);
var Vec3 = new TypedObject.ArrayType(TypedObject.float32, 3);
var Sprite = new TypedObject.ArrayType(Vec3, 3);
var mario = new Sprite();
mario[/\u00ee[]/] = new Vec3([1, 0, 0]);

View File

@ -1,13 +1,13 @@
// Test that we can optimize stuff like line.target.x without
// creating an intermediate object.
if (!this.hasOwnProperty("Type"))
if (!this.hasOwnProperty("TypedObject"))
quit();
var PointType = new StructType({x: float64,
y: float64});
var LineType = new StructType({source: PointType,
target: PointType});
var PointType = new TypedObject.StructType({x: TypedObject.float64,
y: TypedObject.float64});
var LineType = new TypedObject.StructType({source: PointType,
target: PointType});
function manhattenDistance(line) {
return (Math.abs(line.target.x - line.source.x) +

View File

@ -1,12 +1,16 @@
if (!this.hasOwnProperty("Type"))
if (!this.hasOwnProperty("TypedObject"))
quit();
var PointType2 = new StructType({x: float64,
y: float64});
var PointType2 =
new TypedObject.StructType({
x: TypedObject.float64,
y: TypedObject.float64});
var PointType3 = new StructType({x: float64,
y: float64,
z: float64});
var PointType3 =
new TypedObject.StructType({
x: TypedObject.float64,
y: TypedObject.float64,
z: TypedObject.float64});
function xPlusY(p) {
return p.x + p.y;

View File

@ -1,9 +1,9 @@
if (!this.hasOwnProperty("Type"))
if (!this.hasOwnProperty("TypedObject"))
quit();
var PointType = new StructType({x: float64,
y: float64,
z: float64});
var PointType = new TypedObject.StructType({x: TypedObject.float64,
y: TypedObject.float64,
z: TypedObject.float64});
function foo() {
for (var i = 0; i < 30000; i += 3) {

View File

@ -1,9 +1,9 @@
if (!this.hasOwnProperty("Type"))
if (!this.hasOwnProperty("TypedObject"))
quit();
var PointType = new StructType({x: uint32,
y: uint32,
z: uint32});
var PointType = new TypedObject.StructType({x: TypedObject.uint32,
y: TypedObject.uint32,
z: TypedObject.uint32});
function foo() {
for (var i = 0; i < 30000; i += 3) {

View File

@ -1433,7 +1433,7 @@ static const JSStdName standard_class_atoms[] = {
{js_InitIntlClass, EAGER_ATOM_AND_CLASP(Intl)},
#endif
#ifdef ENABLE_BINARYDATA
{js_InitTypedObjectClasses, EAGER_ATOM_AND_CLASP(Type)},
{js_InitTypedObjectClass, EAGER_ATOM_AND_CLASP(TypedObject)},
#endif
{nullptr, 0, nullptr}
};
@ -1491,17 +1491,6 @@ static const JSStdName standard_class_names[] = {
TYPED_ARRAY_CLASP(TYPE_UINT8_CLAMPED)},
{js_InitTypedArrayClasses, EAGER_CLASS_ATOM(DataView), &DataViewObject::class_},
/* Binary Data */
#ifdef ENABLE_BINARYDATA
{js_InitTypedObjectClasses, EAGER_ATOM_AND_CLASP(Type)},
{js_InitTypedObjectClasses, EAGER_ATOM_AND_CLASP(Data)},
#define BINARYDATA_NUMERIC_NAMES(constant_, type_, name_) \
{js_InitTypedObjectClasses, EAGER_CLASS_ATOM(name_), &NumericTypeClasses[constant_]},
JS_FOR_EACH_SCALAR_TYPE_REPR(BINARYDATA_NUMERIC_NAMES)
#undef BINARYDATA_NUMERIC_NAMES
{js_InitTypedObjectClasses, EAGER_CLASS_ATOM(ArrayType), &js::ArrayType::class_},
{js_InitTypedObjectClasses, EAGER_CLASS_ATOM(StructType), &js::StructType::class_},
#endif
{nullptr, 0, nullptr}
};

View File

@ -54,20 +54,7 @@
macro(DataView, 35, js_InitTypedArrayClasses) \
macro(ParallelArray, 36, js_InitParallelArrayClass) \
macro(Intl, 37, js_InitIntlClass) \
macro(Type, 38, js_InitTypedObjectClasses) \
macro(Data, 39, js_InitTypedObjectClasses) \
macro(uint8Clamped, 40, js_InitTypedObjectClasses) \
macro(uint8, 41, js_InitTypedObjectClasses) \
macro(uint16, 42, js_InitTypedObjectClasses) \
macro(uint32, 43, js_InitTypedObjectClasses) \
macro(int8, 44, js_InitTypedObjectClasses) \
macro(int16, 45, js_InitTypedObjectClasses) \
macro(int32, 46, js_InitTypedObjectClasses) \
macro(float32, 47, js_InitTypedObjectClasses) \
macro(float64, 48, js_InitTypedObjectClasses) \
macro(ArrayType, 49, js_InitTypedObjectClasses) \
macro(StructType, 50, js_InitTypedObjectClasses) \
macro(ArrayTypeObject, 51, js_InitTypedObjectClasses) \
macro(GeneratorFunction, 52, js_InitIteratorClasses) \
macro(TypedObject, 38, js_InitTypedObjectDummy) \
macro(GeneratorFunction, 39, js_InitIteratorClasses) \
#endif /* jsprototypes_h */

View File

@ -1,4 +1,5 @@
// |reftest| skip-if(!this.hasOwnProperty("Type"))
// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
var BUGNUMBER = 578700;
var summary = 'Binary Data class diagram';
@ -26,44 +27,29 @@ function assertThrows(f) {
}
function runTests() {
print(BUGNUMBER + ": " + summary);
print(BUGNUMBER + ": " + summary);
assertEq(Data.__proto__, Function.prototype);
assertEq(Data.prototype.__proto__, Object.prototype);
assertEq(Data.prototype.constructor, Data);
assertEq(typeof Data.prototype.update === "function", true);
var ArrayType = TypedObject.ArrayType;
var StructType = TypedObject.StructType;
assertEq(Type.__proto__, Function.prototype);
assertEq(Type.prototype, Data);
assertEq(ArrayType instanceof Function, true);
assertEq(ArrayType.prototype instanceof Function, true);
assertEq(ArrayType.__proto__, Type);
assertEq(ArrayType.prototype.__proto__, Type.prototype);
assertEq(typeof ArrayType.prototype.repeat === "function", true);
assertEq(ArrayType.__proto__, Function.__proto__);
assertEq(ArrayType.prototype.__proto__, Function.__proto__);
assertEq(ArrayType.prototype.prototype.__proto__, Data.prototype);
assertEq(StructType instanceof Function, true);
assertEq(StructType.prototype instanceof Function, true);
assertEq(StructType.__proto__, Type);
assertEq(StructType.prototype.__proto__, Type.prototype);
assertEq(StructType.prototype.prototype.__proto__, Data.prototype);
assertEq(Object.getPrototypeOf(StructType),
Object.getPrototypeOf(Function));
assertEq(Object.getPrototypeOf(StructType.prototype),
Object.getPrototypeOf(Function));
// Change global 'Type' and see if things stay sane.
Type = function() {
return 42;
}
if (typeof reportCompare === "function")
reportCompare(true, true);
Data = function() {
return 43;
}
assertNotEq(ArrayType.prototype.__proto__, Type.prototype);
assertNotEq(ArrayType.prototype.prototype.__proto__, Data.prototype);
assertNotEq(StructType.prototype.__proto__, Type.prototype);
assertNotEq(StructType.prototype.prototype.__proto__, Data.prototype);
if (typeof reportCompare === "function")
reportCompare(true, true);
print("Tests complete");
print("Tests complete");
}
runTests();

View File

@ -1,7 +1,10 @@
// |reftest| skip-if(!this.hasOwnProperty("Type"))
// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
var BUGNUMBER = 578700;
var summary = 'TypedObjects StructType prototype chains';
var ArrayType = TypedObject.ArrayType;
var StructType = TypedObject.StructType;
var float32 = TypedObject.float32;
function runTests() {
var Point = new ArrayType(float32, 3);

View File

@ -1,4 +1,4 @@
// |reftest| skip-if(!this.hasOwnProperty("Type"))
// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
var BUGNUMBER = 578700;
var summary = 'TypedObjects ArrayType implementation';
@ -13,6 +13,11 @@ function assertThrows(f) {
throw new TypeError("Assertion failed: " + f + " did not throw as expected");
}
var ArrayType = TypedObject.ArrayType;
var uint8 = TypedObject.uint8;
var float32 = TypedObject.float32;
var uint32 = TypedObject.uint32;
function runTests() {
print(BUGNUMBER + ": " + summary);
@ -106,17 +111,8 @@ function runTests() {
for (var i = 0; i < c.length; i++)
assertEq(c[i], 3);
assertThrows(function() c.update([3.14, 4.52, 5]));
//assertThrows(function() c.update([3000, 0, 1, 1, 1, 1, 1, 1, 1, 1]));
assertThrows(function() Vec3.prototype.fill.call(c, 2));
var updatingPos = new Vec3();
updatingPos.update([5, 3, 1]);
assertEq(updatingPos[0], 5);
assertEq(updatingPos[1], 3);
assertEq(updatingPos[2], 1);
var d = A.repeat(10);
for (var i = 0; i < d.length; i++)
assertEq(d[i], 10);
@ -137,15 +133,6 @@ function runTests() {
assertThrows(function() ma.subarray({}));
assertThrows(function() ma.subarray(2, []));
// check similarity even though mb's ArrayType
// is not script accessible
var Similar = new ArrayType(uint32, 3);
var sim = new Similar();
sim.update(mb);
assertEq(sim[0], 3);
assertEq(sim[1], 4);
assertEq(sim[2], 5);
var range = ma.subarray(0, 3);
assertEq(range.length, 3);
assertEq(range[0], 1);
@ -181,13 +168,18 @@ function runTests() {
assertEq(indexPropDesc.enumerable, true);
assertEq(indexPropDesc.writable, true);
var lengthPropDesc = Object.getOwnPropertyDescriptor(as, 'length');
assertEq(typeof lengthPropDesc == "undefined", false);
assertEq(lengthPropDesc.configurable, false);
assertEq(lengthPropDesc.enumerable, false);
assertEq(lengthPropDesc.writable, false);
var counter = 0;
for (var nm in as) {
assertEq(+nm, counter++);
}
assertEq(counter, as.length);
assertThrows(function() Object.defineProperty(o, "foo", { value: "bar" }));
// check if a reference acts the way it should

View File

@ -1,4 +1,4 @@
// |reftest| skip-if(!this.hasOwnProperty("Type"))
// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
var BUGNUMBER = 578700;
var summary = 'TypedObjects memory check';
@ -7,6 +7,19 @@ function spin() {
;
}
var ArrayType = TypedObject.ArrayType;
var StructType = TypedObject.StructType;
var uint8 = TypedObject.uint8;
var uint16 = TypedObject.uint16;
var uint32 = TypedObject.uint32;
var uint8Clamped = TypedObject.uint8Clamped;
var int8 = TypedObject.int8;
var int16 = TypedObject.int16;
var int32 = TypedObject.int32;
var float32 = TypedObject.float32;
var float64 = TypedObject.float64;
function runTests() {
print(BUGNUMBER + ": " + summary);
@ -49,7 +62,9 @@ function runTests() {
gc();
spin();
assertEq(middleBand['r'] == 0 && middleBand['g'] == 0 && middleBand['b'] == 0, true);
middleBand.update({'r': 255, 'g': 207, 'b': 142});
middleBand.r = 255;
middleBand.g = 207;
middleBand.b = 142;
assertEq(middleBand['r'] == 255 && middleBand['g'] == 207 && middleBand['b'] == 142, true);
var scopedType = function() {

View File

@ -1,9 +1,21 @@
// |reftest| skip-if(!this.hasOwnProperty("Type"))
// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
var BUGNUMBER = 578700;
var summary = 'TypedObjects numeric types';
var actual = '';
var expect = '';
var ArrayType = TypedObject.ArrayType;
var StructType = TypedObject.StructType;
var uint8 = TypedObject.uint8;
var uint16 = TypedObject.uint16;
var uint32 = TypedObject.uint32;
var uint8Clamped = TypedObject.uint8Clamped;
var int8 = TypedObject.int8;
var int16 = TypedObject.int16;
var int32 = TypedObject.int32;
var float32 = TypedObject.float32;
var float64 = TypedObject.float64;
function runTests()
{
printBugNumber(BUGNUMBER);

View File

@ -1,9 +1,23 @@
// |reftest| skip-if(!this.hasOwnProperty("Type"))
// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
var BUGNUMBER = 578700;
var summary = 'Size and Alignment of TypedObjects types';
var actual = '';
var expect = '';
var ArrayType = TypedObject.ArrayType;
var StructType = TypedObject.StructType;
var uint8 = TypedObject.uint8;
var uint16 = TypedObject.uint16;
var uint32 = TypedObject.uint32;
var uint8Clamped = TypedObject.uint8Clamped;
var int8 = TypedObject.int8;
var int16 = TypedObject.int16;
var int32 = TypedObject.int32;
var float32 = TypedObject.float32;
var float64 = TypedObject.float64;
function runTests() {
printBugNumber(BUGNUMBER);
printStatus(summary);

View File

@ -1,7 +1,19 @@
// |reftest| skip-if(!this.hasOwnProperty("Type"))
// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
var BUGNUMBER = 578700;
var summary = 'TypedObjects Equivalent StructTypes';
var ArrayType = TypedObject.ArrayType;
var StructType = TypedObject.StructType;
var uint8 = TypedObject.uint8;
var uint16 = TypedObject.uint16;
var uint32 = TypedObject.uint32;
var uint8Clamped = TypedObject.uint8Clamped;
var int8 = TypedObject.int8;
var int16 = TypedObject.int16;
var int32 = TypedObject.int32;
var float32 = TypedObject.float32;
var float64 = TypedObject.float64;
function assertEquivalent(t1, t2) {
assertEq(true, t1.equivalent(t2));
assertEq(true, t2.equivalent(t1));

View File

@ -1,7 +1,19 @@
// |reftest| skip-if(!this.hasOwnProperty("Type"))
// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
var BUGNUMBER = 578700;
var summary = 'TypedObjects StructType propery enumeration';
var ArrayType = TypedObject.ArrayType;
var StructType = TypedObject.StructType;
var uint8 = TypedObject.uint8;
var uint16 = TypedObject.uint16;
var uint32 = TypedObject.uint32;
var uint8Clamped = TypedObject.uint8Clamped;
var int8 = TypedObject.int8;
var int16 = TypedObject.int16;
var int32 = TypedObject.int32;
var float32 = TypedObject.float32;
var float64 = TypedObject.float64;
function runTests() {
var RgbColor = new StructType({r: uint8, g: uint8, b: uint8});
var Fade = new StructType({from: RgbColor, to: RgbColor});

View File

@ -1,7 +1,19 @@
// |reftest| skip-if(!this.hasOwnProperty("Type"))
// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
var BUGNUMBER = 578700;
var summary = 'TypedObjects: indexed properties are illegal in a StructType';
var ArrayType = TypedObject.ArrayType;
var StructType = TypedObject.StructType;
var uint8 = TypedObject.uint8;
var uint16 = TypedObject.uint16;
var uint32 = TypedObject.uint32;
var uint8Clamped = TypedObject.uint8Clamped;
var int8 = TypedObject.int8;
var int16 = TypedObject.int16;
var int32 = TypedObject.int32;
var float32 = TypedObject.float32;
var float64 = TypedObject.float64;
function runTests() {
print(BUGNUMBER + ": " + summary);

View File

@ -1,7 +1,18 @@
// |reftest| skip-if(!this.hasOwnProperty("Type"))
// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
var BUGNUMBER = 578700;
var summary = 'TypedObjects StructType prototype chains';
var ArrayType = TypedObject.ArrayType;
var StructType = TypedObject.StructType;
var uint8 = TypedObject.uint8;
var uint16 = TypedObject.uint16;
var uint32 = TypedObject.uint32;
var uint8Clamped = TypedObject.uint8Clamped;
var int8 = TypedObject.int8;
var int16 = TypedObject.int16;
var int32 = TypedObject.int32;
var float32 = TypedObject.float32;
var float64 = TypedObject.float64;
function runTests() {
var RgbColor1 = new StructType({r: uint8, g: uint8, b: uint8});
@ -9,8 +20,9 @@ function runTests() {
var Fade1 = new StructType({from: RgbColor1, to: RgbColor1});
var Fade2 = new StructType({from: RgbColor2, to: RgbColor2});
// Available on all objects
Data.prototype.sub = function(c) {
// Available on all struct types (even though it would only make
// sense on a RgbColor1 or RgbColor2 instance)
StructType.prototype.prototype.sub = function(c) {
this.r -= c;
this.g -= c;
this.b -= c;

View File

@ -1,7 +1,19 @@
// |reftest| skip-if(!this.hasOwnProperty("Type"))
// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
var BUGNUMBER = 578700;
var summary = 'TypedObjects: check reflection on StructType objects';
var ArrayType = TypedObject.ArrayType;
var StructType = TypedObject.StructType;
var uint8 = TypedObject.uint8;
var uint16 = TypedObject.uint16;
var uint32 = TypedObject.uint32;
var uint8Clamped = TypedObject.uint8Clamped;
var int8 = TypedObject.int8;
var int16 = TypedObject.int16;
var int32 = TypedObject.int32;
var float32 = TypedObject.float32;
var float64 = TypedObject.float64;
function runTests() {
print(BUGNUMBER + ": " + summary);

View File

@ -1,7 +1,19 @@
// |reftest| skip-if(!this.hasOwnProperty("Type"))
// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
var BUGNUMBER = 578700;
var summary = 'TypedObjects StructType structural assignment';
var ArrayType = TypedObject.ArrayType;
var StructType = TypedObject.StructType;
var uint8 = TypedObject.uint8;
var uint16 = TypedObject.uint16;
var uint32 = TypedObject.uint32;
var uint8Clamped = TypedObject.uint8Clamped;
var int8 = TypedObject.int8;
var int16 = TypedObject.int16;
var int32 = TypedObject.int32;
var float32 = TypedObject.float32;
var float64 = TypedObject.float64;
function assertEqColor(c1, c2) {
assertEq(c1.r, c2.r);
assertEq(c1.g, c2.g);

View File

@ -15,6 +15,7 @@
macro(anonymous, anonymous, "anonymous") \
macro(apply, apply, "apply") \
macro(arguments, arguments, "arguments") \
macro(ArrayType, ArrayType, "ArrayType") \
macro(buffer, buffer, "buffer") \
macro(builder, builder, "builder") \
macro(byteLength, byteLength, "byteLength") \
@ -62,6 +63,8 @@
macro(fieldTypes, fieldTypes, "fieldTypes") \
macro(fileName, fileName, "fileName") \
macro(fix, fix, "fix") \
macro(float32, float32, "float32") \
macro(float64, float64, "float64") \
macro(format, format, "format") \
macro(get, get, "get") \
macro(getInternals, getInternals, "getInternals") \
@ -85,6 +88,9 @@
macro(isPrototypeOf, isPrototypeOf, "isPrototypeOf") \
macro(iterate, iterate, "iterate") \
macro(Infinity, Infinity, "Infinity") \
macro(int8, int8, "int8") \
macro(int16, int16, "int16") \
macro(int32, int32, "int32") \
macro(iterator, iterator, "iterator") \
macro(iteratorIntrinsic, iteratorIntrinsic, "__iterator__") \
macro(join, join, "join") \
@ -131,6 +137,7 @@
macro(source, source, "source") \
macro(stack, stack, "stack") \
macro(sticky, sticky, "sticky") \
macro(StructType, StructType, "StructType") \
macro(style, style, "style") \
macro(test, test, "test") \
macro(throw, throw_, "throw") \
@ -145,6 +152,10 @@
macro(true, true_, "true") \
macro(unescape, unescape, "unescape") \
macro(uneval, uneval, "uneval") \
macro(uint8, uint8, "uint8") \
macro(uint8Clamped, uint8Clamped, "uint8Clamped") \
macro(uint16, uint16, "uint16") \
macro(uint32, uint32, "uint32") \
macro(unwatch, unwatch, "unwatch") \
macro(url, url, "url") \
macro(usage, usage, "usage") \

View File

@ -26,7 +26,7 @@ extern JSObject *
js_InitTypedArrayClasses(JSContext *cx, js::HandleObject obj);
extern JSObject *
js_InitTypedObjectClasses(JSContext *cx, js::HandleObject obj);
js_InitTypedObjectClass(JSContext *cx, js::HandleObject obj);
namespace js {
@ -108,9 +108,10 @@ class GlobalObject : public JSObject
static const unsigned RUNTIME_CODEGEN_ENABLED = FUNCTION_NS + 1;
static const unsigned DEBUGGERS = RUNTIME_CODEGEN_ENABLED + 1;
static const unsigned INTRINSICS = DEBUGGERS + 1;
static const unsigned ARRAY_TYPE = INTRINSICS + 1;
/* Total reserved-slot count for global objects. */
static const unsigned RESERVED_SLOTS = INTRINSICS + 1;
static const unsigned RESERVED_SLOTS = ARRAY_TYPE + 1;
void staticAsserts() {
/*
@ -415,19 +416,6 @@ class GlobalObject : public JSObject
return &getPrototype(JSProto_Iterator).toObject();
}
JSObject *getOrCreateDataObject(JSContext *cx) {
return getOrCreateObject(cx, APPLICATION_SLOTS + JSProto_Data, initDataObject);
}
JSObject *getOrCreateTypeObject(JSContext *cx) {
return getOrCreateObject(cx, APPLICATION_SLOTS + JSProto_Type, initTypeObject);
}
JSObject *getOrCreateArrayTypeObject(JSContext *cx) {
return getOrCreateObject(cx, APPLICATION_SLOTS + JSProto_ArrayTypeObject,
initArrayTypeObject);
}
JSObject *getOrCreateCollatorPrototype(JSContext *cx) {
return getOrCreateObject(cx, COLLATOR_PROTO, initCollatorProto);
}
@ -440,6 +428,21 @@ class GlobalObject : public JSObject
return getOrCreateObject(cx, DATE_TIME_FORMAT_PROTO, initDateTimeFormatProto);
}
JSObject *getArrayType(JSContext *cx) {
const Value &v = getReservedSlot(ARRAY_TYPE);
MOZ_ASSERT(v.isObject(),
"GlobalObject::arrayType must only be called from "
"TypedObject code that can assume TypedObject has "
"been initialized");
return &v.toObject();
}
void setArrayType(JSObject *obj) {
initReservedSlot(ARRAY_TYPE, ObjectValue(*obj));
}
private:
typedef bool (*ObjectInitOp)(JSContext *cx, Handle<GlobalObject*> global);
@ -569,11 +572,6 @@ class GlobalObject : public JSObject
static bool initNumberFormatProto(JSContext *cx, Handle<GlobalObject*> global);
static bool initDateTimeFormatProto(JSContext *cx, Handle<GlobalObject*> global);
// Implemented in builtin/TypedObject.cpp
static bool initTypeObject(JSContext *cx, Handle<GlobalObject*> global);
static bool initDataObject(JSContext *cx, Handle<GlobalObject*> global);
static bool initArrayTypeObject(JSContext *cx, Handle<GlobalObject*> global);
static bool initStandardClasses(JSContext *cx, Handle<GlobalObject*> global);
typedef js::Vector<js::Debugger *, 0, js::SystemAllocPolicy> DebuggerVector;