Skip to content

Commit 159d514

Browse files
author
wendy@lastlookeditorial.com
committed
Edited ch06.asciidoc with Atlas code editor
1 parent f7b8dd0 commit 159d514

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ch06.asciidoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ For the most part, the traps that we discussed so far have to do with property a
631631
[[getownpropertydescriptor_trap]]
632632
==== getOwnPropertyDescriptor Trap
633633

634-
The `getOwnPropertyDescriptor` trap is triggered when querying an object for the property descriptor for some `key`. It should return a property descriptor or `undefined` when the property doesn't exist. There is also the option of throwing an exception, aborting the operation entirely.
634+
The `getOwnPropertyDescriptor` trap is ((("getOwnPropertyDescriptor trap", id="gopdt6")))((("proxies", "getOwnPropertyDescriptor trap", id="prox6gopdt")))((("traps", "getOwnPropertyDescriptor trap", id="t6gopdt")))triggered when querying an object for the property descriptor for some `key`. It should return a property descriptor or `undefined` when the property doesn't exist. There is also the option of throwing an exception, aborting the operation entirely.
635635

636636
If we go back to the canonical private property space example, we could implement a trap, such as the one in the next code snippet, to prevent consumers from learning about property descriptors of private properties.
637637

@@ -697,7 +697,7 @@ console.log(proxy.hasOwnProperty('_secret'))
697697

698698
When you're trying to hide things, it's best to have them try and behave as if they fell in some other category than the category they're actually in, thus concealing their behavior and passing it off for something else. Throwing, however, sends the wrong message when we want to conceal something: why does a property throw instead of return `undefined`? It must exist but be inaccessible. This is not unlike situations in HTTP API design where we might prefer to return "404 Not Found" responses for sensitive resources, such as an administration backend, when the user is unauthorized to access them, instead of the technically correct "401 Unauthorized" status code.
699699

700-
When debugging concerns outweight security concerns, you should at least consider the `throw` statement. In any case, it's important to understand your use case in order to figure out the optimal and least surprising behavior for a given component.
700+
When debugging concerns outweight security concerns, you should at least consider the `throw` statement. In any case, it's important to understand your use case in order to figure out the optimal and least surprising behavior for a given ((("getOwnPropertyDescriptor trap", startref="gopdt6")))((("proxies", "getOwnPropertyDescriptor trap", startref="prox6gopdt")))((("traps", "getOwnPropertyDescriptor trap", startref="t6gopdt")))component.
701701

702702
==== apply Trap
703703

0 commit comments

Comments
 (0)