forked from microsoft/react-native-macos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share re-defined defineReadOnlyGlobal(...) (facebook#42801)
Summary: Fixes some tech debug Changelog: [Internal] [Fixed] Share re-defined defineReadOnlyGlobal(...) Reviewed By: javache Differential Revision: D53340274
- Loading branch information
1 parent
475a156
commit d21e735
Showing
10 changed files
with
164 additions
and
74 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
23 changes: 23 additions & 0 deletions
23
packages/react-native/ReactCommon/react/jsiutils/CMakeLists.txt
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,23 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
cmake_minimum_required(VERSION 3.13) | ||
set(CMAKE_VERBOSE_MAKEFILE on) | ||
|
||
add_compile_options( | ||
-fexceptions | ||
-frtti | ||
-std=c++20 | ||
-Wall | ||
-Wpedantic | ||
-DLOG_TAG=\"Fabric\") | ||
|
||
file(GLOB react_jsiutils_SRC CONFIGURE_DEPENDS *.cpp) | ||
add_library(react_jsiutils STATIC ${react_jsiutils_SRC}) | ||
|
||
target_include_directories(react_jsiutils PUBLIC ${REACT_COMMON_DIR}) | ||
|
||
target_link_libraries(react_jsiutils | ||
jsireact) |
57 changes: 57 additions & 0 deletions
57
packages/react-native/ReactCommon/react/jsiutils/React-jsiutils.podspec
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,57 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
require "json" | ||
|
||
package = JSON.parse(File.read(File.join(__dir__, "..", "..", "..", "package.json"))) | ||
version = package['version'] | ||
|
||
source = { :git => 'https://github.com/facebook/react-native.git' } | ||
if version == '1000.0.0' | ||
# This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in. | ||
source[:commit] = `git rev-parse HEAD`.strip if system("git rev-parse --git-dir > /dev/null 2>&1") | ||
else | ||
source[:tag] = "v#{version}" | ||
end | ||
|
||
folly_config = get_folly_config() | ||
folly_compiler_flags = folly_config[:compiler_flags] | ||
folly_version = folly_config[:version] | ||
|
||
header_search_paths = [ | ||
"\"$(PODS_TARGET_SRCROOT)\"", | ||
"\"$(PODS_TARGET_SRCROOT)/ReactCommon\"", | ||
] | ||
|
||
Pod::Spec.new do |s| | ||
s.name = "React-jsiutils" | ||
s.version = version | ||
s.summary = "-" # TODO | ||
s.homepage = "https://reactnative.dev/" | ||
s.license = package["license"] | ||
s.author = "Meta Platforms, Inc. and its affiliates" | ||
s.platforms = min_supported_versions | ||
s.source = source | ||
s.source_files = "*.{cpp,h}" | ||
s.compiler_flags = folly_compiler_flags | ||
s.header_dir = "react/jsiutils" | ||
s.exclude_files = "tests" | ||
s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++20", | ||
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '), | ||
"DEFINES_MODULE" => "YES" } | ||
|
||
if ENV['USE_FRAMEWORKS'] | ||
s.module_name = "React_jsiutils" | ||
s.header_mappings_dir = "../.." | ||
end | ||
|
||
s.dependency "React-jsi", version | ||
|
||
if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1" | ||
s.dependency "hermes-engine" | ||
else | ||
s.dependency "React-jsc" | ||
end | ||
end |
39 changes: 39 additions & 0 deletions
39
packages/react-native/ReactCommon/react/jsiutils/globals.cpp
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,39 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "globals.h" | ||
|
||
namespace facebook::react { | ||
|
||
void defineReadOnlyGlobal( | ||
jsi::Runtime& runtime, | ||
const std::string& propName, | ||
jsi::Value&& value) { | ||
auto global = runtime.global(); | ||
if (global.hasProperty(runtime, propName.c_str())) { | ||
throw jsi::JSError( | ||
runtime, | ||
"Tried to redefine read-only global \"" + propName + | ||
"\", but read-only globals can only be defined once."); | ||
} | ||
jsi::Object jsObject = | ||
global.getProperty(runtime, "Object").asObject(runtime); | ||
jsi::Function defineProperty = jsObject.getProperty(runtime, "defineProperty") | ||
.asObject(runtime) | ||
.asFunction(runtime); | ||
|
||
jsi::Object descriptor = jsi::Object(runtime); | ||
descriptor.setProperty(runtime, "value", std::move(value)); | ||
defineProperty.callWithThis( | ||
runtime, | ||
jsObject, | ||
global, | ||
jsi::String::createFromUtf8(runtime, propName), | ||
descriptor); | ||
} | ||
|
||
} // namespace facebook::react |
31 changes: 31 additions & 0 deletions
31
packages/react-native/ReactCommon/react/jsiutils/globals.h
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,31 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <jsi/jsi.h> | ||
#include <string> | ||
|
||
namespace facebook::react { | ||
|
||
/** | ||
* Defines a property on the global object that is neither enumerable, nor | ||
* configurable, nor writable. This ensures that the private globals exposed by | ||
* ReactInstance cannot overwritten by third-party JavaScript code. It also | ||
* ensures that third-party JavaScript code unaware of these globals isn't able | ||
* to accidentally access them. In JavaScript, equivalent to: | ||
* | ||
* Object.defineProperty(global, propName, { | ||
* value: value | ||
* }) | ||
*/ | ||
void defineReadOnlyGlobal( | ||
jsi::Runtime& runtime, | ||
const std::string& propName, | ||
jsi::Value&& value); | ||
|
||
} // namespace facebook::react |
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
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