Skip to content

Commit ca1e589

Browse files
committed
Add explanatory comment
1 parent f51067a commit ca1e589

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

jscomp/runtime/caml_obj.ml

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ module O = struct
3737
[%raw{|function(o,foo){
3838
for (var x in o) { foo(x) }}
3939
|}]
40+
41+
(**
42+
JS objects are not guaranteed to have `Object` in their prototype
43+
chain so calling `some_obj.hasOwnProperty(key)` can sometimes throw
44+
an exception when dealing with JS interop. This mainly occurs when
45+
objects are created via `Object.create(null)`. The only safe way
46+
to call this function is directly, e.g. `Object.prototype.hasOwnProperty.call(some_obj, key)`.
47+
*)
4048
external hasOwnProperty :
4149
t -> key -> bool = "call" [@@bs.scope ("Object", "prototype", "hasOwnProperty")] [@@bs.val]
4250
external get_value : Obj.t -> key -> Obj.t = ""[@@bs.get_index]

0 commit comments

Comments
 (0)