forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptional-fields.js
More file actions
54 lines (44 loc) · 3.15 KB
/
optional-fields.js
File metadata and controls
54 lines (44 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var findTypeForExpression = $vm.findTypeForExpression;
load("./driver/driver.js");
var func;
function wrapper() {
func = function(arg){};
}
wrapper();
// ====== End test cases ======
var obj = {x:20, y:50};
func(obj);
var types = findTypeForExpression(wrapper, "arg");
assert(types.instructionTypeSet.structures.length === 1, "arg should have one structure");
assert(types.instructionTypeSet.structures[0].fields.length === 2, "arg should have two fields");
assert(types.instructionTypeSet.structures[0].fields.indexOf("x") !== -1, "arg should have field: 'x'");
assert(types.instructionTypeSet.structures[0].fields.indexOf("y") !== -1, "arg should have field: 'y'");
assert(types.instructionTypeSet.structures[0].optionalFields.length === 0, "arg should have zero optional fields");
obj.z = 40;
func(obj);
types = findTypeForExpression(wrapper, "arg");
assert(types.instructionTypeSet.structures[0].fields.length === 2, "arg should still have two fields");
assert(types.instructionTypeSet.structures[0].fields.indexOf("x") !== -1, "arg should have field: 'x'");
assert(types.instructionTypeSet.structures[0].fields.indexOf("y") !== -1, "arg should have field: 'y'");
assert(types.instructionTypeSet.structures[0].optionalFields.length === 1, "arg should have one optional field");
assert(types.instructionTypeSet.structures[0].optionalFields.indexOf("z") !== -1, "arg should have optional field: 'z'");
obj["foo"] = "type";
obj["baz"] = "profiler";
func(obj);
types = findTypeForExpression(wrapper, "arg");
assert(types.instructionTypeSet.structures[0].fields.length === 2, "arg should still have two fields");
assert(types.instructionTypeSet.structures[0].fields.indexOf("x") !== -1, "arg should have field: 'x'");
assert(types.instructionTypeSet.structures[0].fields.indexOf("y") !== -1, "arg should have field: 'y'");
assert(types.instructionTypeSet.structures[0].optionalFields.length === 3, "arg should have three optional field");
assert(types.instructionTypeSet.structures[0].optionalFields.indexOf("z") !== -1, "arg should have optional field: 'z'");
assert(types.instructionTypeSet.structures[0].optionalFields.indexOf("foo") !== -1, "arg should have optional field: 'foo'");
assert(types.instructionTypeSet.structures[0].optionalFields.indexOf("baz") !== -1, "arg should have optional field: 'baz'");
func({});
types = findTypeForExpression(wrapper, "arg");
assert(types.instructionTypeSet.structures[0].fields.length === 0, "arg should have no common fields");
assert(types.instructionTypeSet.structures[0].optionalFields.length === 5, "arg should have five optional field");
assert(types.instructionTypeSet.structures[0].optionalFields.indexOf("x") !== -1, "arg should have optional field: 'x'");
assert(types.instructionTypeSet.structures[0].optionalFields.indexOf("y") !== -1, "arg should have optional field: 'y'");
assert(types.instructionTypeSet.structures[0].optionalFields.indexOf("z") !== -1, "arg should have optional field: 'z'");
assert(types.instructionTypeSet.structures[0].optionalFields.indexOf("foo") !== -1, "arg should have optional field: 'foo'");
assert(types.instructionTypeSet.structures[0].optionalFields.indexOf("baz") !== -1, "arg should have optional field: 'baz'");