Commit 7973bd3
n-api: Implement stricter wrapping
Use a stronger criterion to identify objects in the prototype chain that store
pointers to native data that were added by previous calls to `napi_wrap()`.
Whereas the old criterion for identifying `napi_wrap()`-injected prototype
chain objects was to consider an object with an internal field
count of 1 to be such an object, the new criterion is to consider an object
with an internal field count of 2 such that the second field holds a
`v8::External` which itself contains a pointer to a global static string unique
to N-API to be a `napi_wrap()`-injected prototype chain object.
This greatly reduces the possibility of returning a pointer that was not
previously added with `napi_wrap()`, and it allows us to recognize that an
object has already undergone `napi_wrap()` and we can thus prevent a chain of
wrappers only the first of which is accessible from appearing in the prototype
chain, as would be the result of multiple calls to `napi_wrap()` using the same
object.
Backport-PR-URL: #19447
PR-URL: #13872
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>1 parent 5b0c57c commit 7973bd3
File tree
4 files changed
+83
-16
lines changed- doc/api
- src
- test/addons-napi/test_general
4 files changed
+83
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2876 | 2876 | | |
2877 | 2877 | | |
2878 | 2878 | | |
2879 | | - | |
2880 | | - | |
| 2879 | + | |
| 2880 | + | |
2881 | 2881 | | |
2882 | 2882 | | |
2883 | 2883 | | |
| |||
2905 | 2905 | | |
2906 | 2906 | | |
2907 | 2907 | | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
2908 | 2912 | | |
2909 | 2913 | | |
2910 | 2914 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
678 | 678 | | |
679 | 679 | | |
680 | 680 | | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
681 | 713 | | |
682 | 714 | | |
683 | 715 | | |
| |||
2049 | 2081 | | |
2050 | 2082 | | |
2051 | 2083 | | |
2052 | | - | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
2053 | 2089 | | |
2054 | | - | |
2055 | | - | |
2056 | | - | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
2057 | 2100 | | |
2058 | 2101 | | |
2059 | 2102 | | |
| |||
2090 | 2133 | | |
2091 | 2134 | | |
2092 | 2135 | | |
2093 | | - | |
2094 | | - | |
2095 | | - | |
2096 | | - | |
2097 | | - | |
2098 | | - | |
2099 | | - | |
2100 | | - | |
2101 | | - | |
2102 | | - | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + | |
2103 | 2139 | | |
2104 | 2140 | | |
2105 | 2141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
122 | 140 | | |
123 | 141 | | |
124 | 142 | | |
| |||
130 | 148 | | |
131 | 149 | | |
132 | 150 | | |
| 151 | + | |
133 | 152 | | |
134 | 153 | | |
135 | 154 | | |
| |||
0 commit comments