-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
tools: fix js2c regression #27980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tools: fix js2c regression #27980
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #include "node_native_module.h" | ||
|
|
||
| #include "gtest/gtest.h" | ||
| #include "node_test_fixture.h" | ||
|
|
||
| #include <string> | ||
|
|
||
|
|
||
| using node::native_module::NativeModuleLoader; | ||
| using node::native_module::NativeModuleRecordMap; | ||
|
|
||
| class PerProcessTest : public ::testing::Test { | ||
| protected: | ||
| static const NativeModuleRecordMap get_sources_for_test() { | ||
| return NativeModuleLoader::instance_.source_; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The builds are failing because this is private. I guess it would also make sense to add a public method to just return the source in a copy, though.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made it a friend
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like it was a namespace issue |
||
| } | ||
| }; | ||
|
|
||
| namespace { | ||
|
|
||
| TEST_F(PerProcessTest, EmbeddedSources) { | ||
| const auto& sources = PerProcessTest::get_sources_for_test(); | ||
| ASSERT_TRUE( | ||
| std::any_of(sources.cbegin(), sources.cend(), | ||
| [](auto p){ return p.second.is_one_byte(); })) | ||
| << "NativeModuleLoader::source_ should have some 8bit items"; | ||
|
|
||
| ASSERT_TRUE( | ||
| std::any_of(sources.cbegin(), sources.cend(), | ||
| [](auto p){ return !p.second.is_one_byte(); })) | ||
| << "NativeModuleLoader::source_ should have some 16bit items"; | ||
| } | ||
|
|
||
| } // end namespace | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,6 +200,12 @@ def ReadMacros(macro_files): | |
| }} // namespace node | ||
| """ | ||
|
|
||
| ONE_BYTE_STRING = """ | ||
| static const uint8_t {0}[] = {{ | ||
| {1} | ||
| }}; | ||
| """ | ||
|
|
||
| TWO_BYTE_STRING = """ | ||
| static const uint16_t {0}[] = {{ | ||
| {1} | ||
|
|
@@ -215,15 +221,22 @@ def ReadMacros(macro_files): | |
| is_verbose = False | ||
|
|
||
| def GetDefinition(var, source, step=30): | ||
| encoded_source = bytearray(source, 'utf-16le') | ||
| code_points = [encoded_source[i] + (encoded_source[i+1] * 256) for i in range(0, len(encoded_source), 2)] | ||
| template = ONE_BYTE_STRING | ||
| code_points = [ord(c) for c in source] | ||
| if any(c > 127 for c in code_points): | ||
| template = TWO_BYTE_STRING | ||
| # Treat non-ASCII as UTF-8 and encode as UTF-16 Little Endian. | ||
| encoded_source = bytearray(source, 'utf-16le') | ||
| code_points = [encoded_source[i] + (encoded_source[i + 1] * 256) for i in range(0, len(encoded_source), 2)] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you wrap this, e.g. by putting the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
|
||
| # For easier debugging, align to the common 3 char for code-points. | ||
| elements_s = ['%3s' % x for x in code_points] | ||
| # Put no more then `step` code-points in a line. | ||
| slices = [elements_s[i:i + step] for i in range(0, len(elements_s), step)] | ||
| lines = [','.join(s) for s in slices] | ||
| array_content = ',\n'.join(lines) | ||
| definition = TWO_BYTE_STRING.format(var, array_content) | ||
| definition = template.format(var, array_content) | ||
|
|
||
| return definition, len(code_points) | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.