-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced Reflect with ReflectAdapter (#48000)
On some runtimes, `Reflect` is not available. This creates a new "naive" implementation.
- Loading branch information
Showing
7 changed files
with
68 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/next/src/server/web/spec-extension/adapters/reflect.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export class ReflectAdapter { | ||
static get<T extends object>( | ||
target: T, | ||
prop: string | symbol, | ||
receiver: unknown | ||
): any { | ||
const value = Reflect.get(target, prop, receiver) | ||
if (typeof value === 'function') { | ||
return value.bind(target) | ||
} | ||
|
||
return value | ||
} | ||
|
||
static set<T extends object>( | ||
target: T, | ||
prop: string | symbol, | ||
value: any, | ||
receiver: any | ||
): boolean { | ||
return Reflect.set(target, prop, value, receiver) | ||
} | ||
|
||
static has<T extends object>(target: T, prop: string | symbol): boolean { | ||
return Reflect.has(target, prop) | ||
} | ||
|
||
static deleteProperty<T extends object>( | ||
target: T, | ||
prop: string | symbol | ||
): boolean { | ||
return Reflect.deleteProperty(target, prop) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters