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

Commit

Permalink
Add more safety chekc when creating blob
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoCaso committed Jan 19, 2022
1 parent 5f9cec8 commit f0c8e99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions snapshot_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func (s *SnapshotCreator) Create(functionCode FunctionCodeHandling) (*StartupDat
return nil, errors.New("v8go: Cannot use snapshot creator after creating the blob")
}

if s.ctx == nil {
return nil, errors.New("v8go: Cannot create a snapshot without first adding a context")
}

rtn := C.CreateBlob(s.ptr, s.ctx.ptr, C.int(functionCode))

s.ptr = nil
Expand Down
10 changes: 10 additions & 0 deletions snapshot_creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,13 @@ func TestCreateSnapshotErrorAfterSuccessfullCreate(t *testing.T) {
t.Error("Creating snapshot should have fail")
}
}

func TestCreateSnapshotErrorIfNoContextIsAdded(t *testing.T) {
snapshotCreator := v8.NewSnapshotCreator()

_, err := snapshotCreator.Create(v8.FunctionCodeHandlingKlear)

if err == nil {
t.Error("Creating a snapshop should have fail")
}
}

0 comments on commit f0c8e99

Please sign in to comment.