Skip to content

Commit 0718623

Browse files
committed
Implement Object.prototype.isPropertyOf
JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
1 parent b8e4328 commit 0718623

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,48 @@ static ecma_completion_value_t
189189
ecma_builtin_object_prototype_object_is_prototype_of (ecma_value_t this_arg, /**< this argument */
190190
ecma_value_t arg) /**< routine's first argument */
191191
{
192-
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
192+
/* 1. Is the argument an object? */
193+
if (!ecma_is_value_object (arg))
194+
{
195+
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
196+
}
197+
198+
ecma_completion_value_t return_value = ecma_make_empty_completion_value ();
199+
200+
/* 2. ToObject(this) */
201+
ECMA_TRY_CATCH (obj_value,
202+
ecma_op_to_object (this_arg),
203+
return_value);
204+
205+
ecma_object_t *obj_p = ecma_get_object_from_value (obj_value);
206+
207+
/* 3. Compare prototype to object */
208+
ECMA_TRY_CATCH (v_obj_value,
209+
ecma_op_to_object (arg),
210+
return_value);
211+
212+
ecma_object_t *v_obj_p = ecma_get_object_from_value (v_obj_value);
213+
214+
do
215+
{
216+
v_obj_p = ecma_get_object_prototype (v_obj_p);
217+
if (v_obj_p == NULL)
218+
{
219+
return_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
220+
break;
221+
}
222+
else if (v_obj_p == obj_p)
223+
{
224+
return_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
225+
break;
226+
}
227+
} while (true);
228+
229+
ECMA_FINALIZE (v_obj_value);
230+
231+
ECMA_FINALIZE (obj_value);
232+
233+
return return_value;
193234
} /* ecma_builtin_object_prototype_object_is_prototype_of */
194235

195236
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2015 Samsung Electronics Co., Ltd.
2+
// Copyright 2015 University of Szeged.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
function Function_A() { }
17+
function Function_B() { }
18+
Function_B.prototype = new Function_A();
19+
20+
function Function_C() { }
21+
Function_C.prototype = new Function_B();
22+
23+
function Function_D() { }
24+
Function_D.prototype = new Function_C();
25+
26+
var d_instance = new Function_D();
27+
28+
assert (Function_A.prototype.isPrototypeOf (d_instance) === true)
29+
assert (Function_A.prototype.isPrototypeOf (Array) === false)
30+
31+
32+
assert (Function_A.prototype.isPrototypeOf.call(0, 0) === false);
33+
assert (Function_A.prototype.isPrototypeOf.call(Function_A, 0) === false);

0 commit comments

Comments
 (0)