@@ -31,6 +31,9 @@ static njs_int_t njs_object_define_properties(njs_vm_t *vm, njs_value_t *args,
3131 njs_uint_t nargs , njs_index_t unused , njs_value_t * retval );
3232static njs_int_t njs_object_set_prototype (njs_vm_t * vm , njs_object_t * object ,
3333 const njs_value_t * value );
34+ static njs_int_t njs_object_prototype_has_own_property (njs_vm_t * vm ,
35+ njs_value_t * args , njs_uint_t nargs , njs_index_t magic ,
36+ njs_value_t * retval );
3437
3538
3639njs_object_t *
@@ -2274,8 +2277,10 @@ static const njs_object_prop_init_t njs_object_constructor_properties[] =
22742277 NJS_DECLARE_PROP_NATIVE (STRING_assign , njs_object_assign , 2 , 0 ),
22752278
22762279 NJS_DECLARE_PROP_NATIVE (STRING_is , njs_object_is , 2 , 0 ),
2277- };
22782280
2281+ NJS_DECLARE_PROP_NATIVE (STRING_hasOwn ,
2282+ njs_object_prototype_has_own_property , 2 , 1 ),
2283+ };
22792284
22802285const njs_object_init_t njs_object_constructor_init = {
22812286 njs_object_constructor_properties ,
@@ -2590,27 +2595,47 @@ njs_object_to_string(njs_vm_t *vm, njs_value_t *this, njs_value_t *retval)
25902595
25912596static njs_int_t
25922597njs_object_prototype_has_own_property (njs_vm_t * vm , njs_value_t * args ,
2593- njs_uint_t nargs , njs_index_t unused , njs_value_t * retval )
2598+ njs_uint_t nargs , njs_index_t magic , njs_value_t * retval )
25942599{
25952600 njs_int_t ret ;
25962601 njs_value_t * value , * property , lvalue ;
25972602 njs_property_query_t pq ;
25982603
2599- property = njs_lvalue_arg (& lvalue , args , nargs , 1 );
26002604
2601- if (njs_slow_path (!njs_is_key (property ))) {
2602- ret = njs_value_to_key (vm , property , property );
2603- if (njs_slow_path (ret != NJS_OK )) {
2605+ value = njs_argument (args , magic );
2606+ property = njs_lvalue_arg (& lvalue , args , nargs , 1 + magic );
2607+
2608+ if (magic == 0 ) {
2609+ /* hasOwnProperty. */
2610+
2611+ if (njs_slow_path (!njs_is_key (property ))) {
2612+ ret = njs_value_to_key (vm , property , property );
2613+ if (njs_slow_path (ret != NJS_OK )) {
2614+ return NJS_ERROR ;
2615+ }
2616+ }
2617+
2618+ if (njs_is_null_or_undefined (value )) {
2619+ njs_type_error (vm , "cannot convert %s argument to object" ,
2620+ njs_type_string (value -> type ));
26042621 return NJS_ERROR ;
26052622 }
2606- }
26072623
2608- value = njs_argument (args , 0 );
2624+ } else {
2625+ /* hasOwn. */
26092626
2610- if (njs_is_null_or_undefined (value )) {
2611- njs_type_error (vm , "cannot convert %s argument to object" ,
2612- njs_type_string (value -> type ));
2613- return NJS_ERROR ;
2627+ if (njs_is_null_or_undefined (value )) {
2628+ njs_type_error (vm , "cannot convert %s argument to object" ,
2629+ njs_type_string (value -> type ));
2630+ return NJS_ERROR ;
2631+ }
2632+
2633+ if (njs_slow_path (!njs_is_key (property ))) {
2634+ ret = njs_value_to_key (vm , property , property );
2635+ if (njs_slow_path (ret != NJS_OK )) {
2636+ return NJS_ERROR ;
2637+ }
2638+ }
26142639 }
26152640
26162641 njs_property_query_init (& pq , NJS_PROPERTY_QUERY_GET , 1 );
0 commit comments