-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
feat: add structured cloning to Deno.core #9458
Merged
bartlomieju
merged 10 commits into
denoland:master
from
inteon:add_serialize_deserialize
Feb 16, 2021
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
52d22d5
add structured cloning to deno core
inteon 870148a
lint + format
inteon 5221ce3
fix rusty_v8 bug & remove arraybuffer logic
inteon 11a372f
simplify serialize deserialize
inteon 6da4940
format
inteon 92aef30
Merge branch 'master' of https://github.com/denoland/deno into add_se…
inteon 6129151
Merge branch 'master' of https://github.com/denoland/deno into add_se…
inteon d9b9388
Merge branch 'master' into add_serialize_deserialize
bartlomieju a3c1a32
cleanup
bartlomieju 3f43c21
reset CI
bartlomieju File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. | ||
"use strict"; | ||
|
||
function assert(cond) { | ||
if (!cond) { | ||
throw Error("assert"); | ||
} | ||
} | ||
|
||
function assertArrayEquals(a1, a2) { | ||
if (a1.length !== a2.length) throw Error("assert"); | ||
|
||
for (const index in a1) { | ||
if (a1[index] !== a2[index]) { | ||
throw Error("assert"); | ||
} | ||
} | ||
} | ||
|
||
function main() { | ||
const emptyString = ""; | ||
const emptyStringSerialized = [34, 0]; | ||
assertArrayEquals(Deno.core.serialize(emptyString), emptyStringSerialized); | ||
assert( | ||
Deno.core.deserialize(new Uint8Array(emptyStringSerialized)) === | ||
emptyString, | ||
); | ||
|
||
const primitiveValueArray = ["test", "a", null, undefined]; | ||
// deno-fmt-ignore | ||
const primitiveValueArraySerialized = [ | ||
65, 4, 34, 4, 116, 101, 115, 116, | ||
34, 1, 97, 48, 95, 36, 0, 4, | ||
]; | ||
assertArrayEquals( | ||
Deno.core.serialize(primitiveValueArray), | ||
primitiveValueArraySerialized, | ||
); | ||
|
||
assertArrayEquals( | ||
Deno.core.deserialize( | ||
new Uint8Array(primitiveValueArraySerialized), | ||
), | ||
primitiveValueArray, | ||
); | ||
|
||
const circularObject = { test: null, test2: "dd", test3: "aa" }; | ||
circularObject.test = circularObject; | ||
// deno-fmt-ignore | ||
const circularObjectSerialized = [ | ||
111, 34, 4, 116, 101, 115, 116, 94, | ||
0, 34, 5, 116, 101, 115, 116, 50, | ||
34, 2, 100, 100, 34, 5, 116, 101, | ||
115, 116, 51, 34, 2, 97, 97, 123, | ||
3, | ||
]; | ||
|
||
assertArrayEquals( | ||
Deno.core.serialize(circularObject), | ||
circularObjectSerialized, | ||
); | ||
|
||
const deserializedCircularObject = Deno.core.deserialize( | ||
new Uint8Array(circularObjectSerialized), | ||
); | ||
assert(deserializedCircularObject.test == deserializedCircularObject); | ||
} | ||
|
||
main(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What unused variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is required by
v8::ValueSerializerImpl
but is never used incore/bindings.rs
(yet I think)