Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

SnapshotCreator API test v2 #43

Merged
merged 9 commits into from
Jan 19, 2022
Merged

Conversation

GustavoCaso
Copy link

@GustavoCaso GustavoCaso commented Jan 18, 2022

Change snapshot creator API to:

func TestCreateSnapshot(t *testing.T) {
	snapshotCreator := v8.NewSnapshotCreator()
	snapshotCreatorIso := snapshotCreator.GetIsolate()
	snapshotCreatoCtx := v8.NewContext(snapshotCreatorIso)
	defer snapshotCreatoCtx.Close()

	snapshotCreatoCtx.RunScript(`const add = (a, b) => a + b`, "add.js")
	snapshotCreatoCtx.RunScript(`function run() { return add(3, 4); }`, "main.js")
	snapshotCreator.AddContext(snapshotCreatoCtx)

	data, err := snapshotCreator.Create(v8.FunctionCodeHandlingKlear)
	fatalIf(t, err)
        defer data.Dispose()

	iso := v8.NewIsolate(v8.WithStartupData(data))
	defer iso.Dispose()

	ctx := v8.NewContext(iso)
	defer ctx.Close()

	runVal, err := ctx.Global().Get("run")
	if err != nil {
		panic(err)
	}

	fn, err := runVal.AsFunction()
	if err != nil {
		panic(err)
	}
	val, err := fn.Call(v8.Undefined(iso))
	if err != nil {
		panic(err)
	}
	if val.String() != "7" {
		t.Fatal("invalid val")
	}
}

@GustavoCaso GustavoCaso force-pushed the heap-snapshot-experimentv2 branch from 572ebbe to 93bdd82 Compare January 18, 2022 10:26
@GustavoCaso GustavoCaso force-pushed the heap-snapshot-experimentv2 branch 2 times, most recently from f1f3524 to 30216f7 Compare January 18, 2022 18:02
@GustavoCaso GustavoCaso changed the title Remove passing options to NewSnapshotCreator SnapshotCreator API test v2 Jan 18, 2022
@GustavoCaso GustavoCaso mentioned this pull request Jan 18, 2022
@GustavoCaso GustavoCaso force-pushed the heap-snapshot-experimentv2 branch from 30216f7 to 7c3a420 Compare January 19, 2022 07:55
@GustavoCaso GustavoCaso force-pushed the heap-snapshot-experimentv2 branch from 6752e1c to d1b11a5 Compare January 19, 2022 11:30
@GustavoCaso GustavoCaso force-pushed the heap-snapshot-experimentv2 branch from a09cb03 to f662b53 Compare January 19, 2022 13:37
@GustavoCaso GustavoCaso marked this pull request as ready for review January 19, 2022 14:55
@GustavoCaso GustavoCaso merged commit 5f9cec8 into heap-snapshots Jan 19, 2022
@GustavoCaso GustavoCaso deleted the heap-snapshot-experimentv2 branch January 19, 2022 14:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant