Skip to content

Commit 1c19e5c

Browse files
Zsolt Borbélygalpeter
authored andcommitted
Fix the Object.getPrototypeOf function.
Related issue: #208 JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély [email protected]
1 parent d7ecd4a commit 1c19e5c

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-object.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,17 @@ ecma_builtin_object_object_get_prototype_of (ecma_value_t this_arg __attr_unused
128128
{
129129
/* 2. */
130130
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
131-
132131
ecma_object_t *prototype_p = ecma_get_object_prototype (obj_p);
133-
ecma_ref_object (prototype_p);
134132

135-
ret_value = ecma_make_normal_completion_value (ecma_make_object_value (prototype_p));
133+
if (prototype_p)
134+
{
135+
ret_value = ecma_make_normal_completion_value (ecma_make_object_value (prototype_p));
136+
ecma_ref_object (prototype_p);
137+
}
138+
else
139+
{
140+
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_NULL);
141+
}
136142
}
137143

138144
return ret_value;

tests/jerry/object-create.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ try {
128128
// Create an object with null as prototype
129129
var obj = Object.create(null)
130130
assert (typeof (obj) === "object");
131-
// FIXME: enable this assertion after the #208 is fixed.
132-
// assert (Object.getPrototypeOf (obj) === null);
131+
assert (Object.getPrototypeOf (obj) === null);
133132

134133
try {
135134
Object.create()

tests/jerry/object-getprototypeof.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,21 @@ try {
3535
assert (e instanceof TypeError);
3636
}
3737

38+
try {
39+
var y = Object.getPrototypeOf(null);
40+
assert (false);
41+
} catch (e) {
42+
assert (e instanceof TypeError);
43+
}
44+
3845
var obj = { x : "foo" };
39-
assert (Object.getPrototypeOf(obj) === Object.prototype)
46+
assert (Object.getPrototypeOf(obj) === Object.prototype);
4047

4148
var constructor = function () {};
4249
constructor.prototype = obj;
4350

4451
var d_obj = new constructor();
4552
assert (Object.getPrototypeOf(d_obj) === obj);
53+
54+
obj = Object.create(null);
55+
assert (Object.getPrototypeOf(obj) === null);

0 commit comments

Comments
 (0)