-
-
Notifications
You must be signed in to change notification settings - Fork 35k
src: use Blob{Des|S}erializer for SEA blobs #47962
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
Changes from 1 commit
66c599a
7f90459
1e4dfec
a1ca8dc
87c72f7
ef3fb40
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,8 +13,8 @@ | |||||
|
|
||||||
| #include "debug_utils-inl.h" | ||||||
|
|
||||||
| // This is related to the blob that is used in snapshots and has nothing to do | ||||||
| // with `node_blob.h`. | ||||||
| // This is related to the blob that is used in snapshots and single executable | ||||||
| // applications and has nothing to do with `node_blob.h`. | ||||||
|
|
||||||
| namespace node { | ||||||
|
|
||||||
|
|
@@ -131,25 +131,17 @@ std::vector<T> BlobDeserializer<Impl>::ReadVector() { | |||||
| template <typename Impl> | ||||||
| std::string BlobDeserializer<Impl>::ReadString() { | ||||||
| std::string_view view = ReadStringView(); | ||||||
| std::string result(view.data(), | ||||||
| view.size()); // This creates a copy of view.data. | ||||||
| return result; | ||||||
| Debug("ReadString(), length=%zu: \"%s\"\n", view.size(), view.data()); | ||||||
joyeecheung marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| return std::string(view); | ||||||
| } | ||||||
|
|
||||||
| template <typename Impl> | ||||||
| std::string_view BlobDeserializer<Impl>::ReadStringView() { | ||||||
| size_t length = ReadArithmetic<size_t>(); | ||||||
| Debug("ReadStringView(), length=%zu: ", length); | ||||||
|
|
||||||
| if (is_debug) { | ||||||
| Debug("ReadStringView(), length=%d: ", length); | ||||||
| } | ||||||
|
|
||||||
| CHECK_GT(length, 0); // There should be no empty strings. | ||||||
| std::string_view result(sink.data() + read_total, length); | ||||||
|
|
||||||
| if (is_debug) { | ||||||
| Debug("\"%s\", read %zu bytes\n", result.data(), result.size()); | ||||||
| } | ||||||
| Debug("%p, read %zu bytes\n", result.data(), result.size()); | ||||||
|
|
||||||
| read_total += length; | ||||||
| return result; | ||||||
|
|
@@ -268,29 +260,22 @@ size_t BlobSerializer<Impl>::WriteVector(const std::vector<T>& data) { | |||||
| // [ 4/8 bytes ] length | ||||||
| // [ |length| bytes ] contents | ||||||
| template <typename Impl> | ||||||
| size_t BlobSerializer<Impl>::WriteStringView(const std::string_view& data) { | ||||||
| CHECK_GT(data.size(), 0); // No empty strings should be written. | ||||||
| size_t BlobSerializer<Impl>::WriteStringView(std::string_view data) { | ||||||
| size_t written_total = WriteArithmetic<size_t>(data.size()); | ||||||
| if (is_debug) { | ||||||
| Debug("WriteStringView(), length=%zu: %p\n", data.size(), data.data()); | ||||||
| } | ||||||
| Debug("WriteStringView(), length=%zu: %p\n", data.size(), data.data()); | ||||||
|
|
||||||
| size_t length = data.size(); | ||||||
| sink.insert(sink.end(), data.data(), data.data() + length); | ||||||
| written_total += length; | ||||||
|
|
||||||
| if (is_debug) { | ||||||
| Debug("WriteString() wrote %zu bytes\n", written_total); | ||||||
| } | ||||||
| Debug("WriteStringView() wrote %zu bytes\n", written_total); | ||||||
|
|
||||||
| return written_total; | ||||||
| } | ||||||
|
|
||||||
| template <typename Impl> | ||||||
| size_t BlobSerializer<Impl>::WriteString(const std::string& data) { | ||||||
|
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.
Suggested change
Member
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. This is the method that writes strings (which logs the string directly in debug mode). The one that doesn't is |
||||||
| if (is_debug) { | ||||||
| Debug("WriteString(), length=%zu: \"%s\"\n", data.size(), data.data()); | ||||||
| } | ||||||
| Debug("WriteString(), length=%zu: \"%s\"\n", data.size(), data.data()); | ||||||
| return WriteStringView(data); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| 'use strict'; | ||
|
|
||
| require('../common'); | ||
|
|
||
| const { | ||
| injectAndCodeSign, | ||
| skipIfSingleExecutableIsNotSupported, | ||
| } = require('../common/sea'); | ||
|
|
||
| skipIfSingleExecutableIsNotSupported(); | ||
|
|
||
| // This tests the creation of a single executable application. | ||
joyeecheung marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const tmpdir = require('../common/tmpdir'); | ||
| const { copyFileSync, writeFileSync, existsSync } = require('fs'); | ||
| const { execFileSync } = require('child_process'); | ||
| const { join } = require('path'); | ||
| const assert = require('assert'); | ||
|
|
||
| const configFile = join(tmpdir.path, 'sea-config.json'); | ||
| const seaPrepBlob = join(tmpdir.path, 'sea-prep.blob'); | ||
| const outputFile = join(tmpdir.path, process.platform === 'win32' ? 'sea.exe' : 'sea'); | ||
|
|
||
| tmpdir.refresh(); | ||
|
|
||
| writeFileSync(join(tmpdir.path, 'empty.js'), '', 'utf-8'); | ||
| writeFileSync(configFile, ` | ||
| { | ||
| "main": "empty.js", | ||
| "output": "sea-prep.blob" | ||
| } | ||
| `); | ||
|
|
||
| execFileSync(process.execPath, ['--experimental-sea-config', 'sea-config.json'], { | ||
| cwd: tmpdir.path | ||
| }); | ||
|
|
||
| assert(existsSync(seaPrepBlob)); | ||
|
|
||
| copyFileSync(process.execPath, outputFile); | ||
| injectAndCodeSign(outputFile, seaPrepBlob); | ||
|
|
||
| execFileSync(outputFile); | ||
Uh oh!
There was an error while loading. Please reload this page.