|
| 1 | +// This file is generated. Do not edit. |
| 2 | + |
| 3 | +package v8host |
| 4 | + |
| 5 | +import ( |
| 6 | + "errors" |
| 7 | + dominterfaces "github.com/gost-dom/browser/internal/interfaces/dom-interfaces" |
| 8 | + log "github.com/gost-dom/browser/internal/log" |
| 9 | + v8 "github.com/gost-dom/v8go" |
| 10 | +) |
| 11 | + |
| 12 | +func init() { |
| 13 | + registerJSClass("MutationObserver", "", createMutationObserverPrototype) |
| 14 | +} |
| 15 | + |
| 16 | +type mutationObserverV8Wrapper struct { |
| 17 | + handleReffedObject[dominterfaces.MutationObserver] |
| 18 | +} |
| 19 | + |
| 20 | +func newMutationObserverV8Wrapper(scriptHost *V8ScriptHost) *mutationObserverV8Wrapper { |
| 21 | + return &mutationObserverV8Wrapper{newHandleReffedObject[dominterfaces.MutationObserver](scriptHost)} |
| 22 | +} |
| 23 | + |
| 24 | +func createMutationObserverPrototype(scriptHost *V8ScriptHost) *v8.FunctionTemplate { |
| 25 | + iso := scriptHost.iso |
| 26 | + wrapper := newMutationObserverV8Wrapper(scriptHost) |
| 27 | + constructor := v8.NewFunctionTemplateWithError(iso, wrapper.Constructor) |
| 28 | + |
| 29 | + instanceTmpl := constructor.InstanceTemplate() |
| 30 | + instanceTmpl.SetInternalFieldCount(1) |
| 31 | + |
| 32 | + wrapper.installPrototype(constructor.PrototypeTemplate()) |
| 33 | + |
| 34 | + return constructor |
| 35 | +} |
| 36 | +func (w mutationObserverV8Wrapper) installPrototype(prototypeTmpl *v8.ObjectTemplate) { |
| 37 | + iso := w.scriptHost.iso |
| 38 | + prototypeTmpl.Set("observe", v8.NewFunctionTemplateWithError(iso, w.observe)) |
| 39 | + prototypeTmpl.Set("disconnect", v8.NewFunctionTemplateWithError(iso, w.disconnect)) |
| 40 | + prototypeTmpl.Set("takeRecords", v8.NewFunctionTemplateWithError(iso, w.takeRecords)) |
| 41 | +} |
| 42 | + |
| 43 | +func (w mutationObserverV8Wrapper) Constructor(info *v8.FunctionCallbackInfo) (*v8.Value, error) { |
| 44 | + args := newArgumentHelper(w.scriptHost, info) |
| 45 | + callback, err1 := tryParseArg(args, 0, w.decodeMutationCallback) |
| 46 | + ctx := w.mustGetContext(info) |
| 47 | + if args.noOfReadArguments >= 1 { |
| 48 | + if err1 != nil { |
| 49 | + return nil, err1 |
| 50 | + } |
| 51 | + return w.CreateInstance(ctx, info.This(), callback) |
| 52 | + } |
| 53 | + return nil, errors.New("MutationObserver.constructor: Missing arguments") |
| 54 | +} |
| 55 | + |
| 56 | +func (w mutationObserverV8Wrapper) observe(info *v8.FunctionCallbackInfo) (*v8.Value, error) { |
| 57 | + log.Debug(w.logger(info), "V8 Function call: MutationObserver.observe") |
| 58 | + args := newArgumentHelper(w.scriptHost, info) |
| 59 | + instance, err0 := w.getInstance(info) |
| 60 | + target, err1 := tryParseArg(args, 0, w.decodeNode) |
| 61 | + options, err2 := tryParseArg(args, 1, w.decodeMutationObserverInit) |
| 62 | + if args.noOfReadArguments >= 2 { |
| 63 | + err := errors.Join(err0, err1, err2) |
| 64 | + if err != nil { |
| 65 | + return nil, err |
| 66 | + } |
| 67 | + callErr := instance.Observe(target, options...) |
| 68 | + return nil, callErr |
| 69 | + } |
| 70 | + return nil, errors.New("MutationObserver.observe: Missing arguments") |
| 71 | +} |
| 72 | + |
| 73 | +func (w mutationObserverV8Wrapper) disconnect(info *v8.FunctionCallbackInfo) (*v8.Value, error) { |
| 74 | + log.Debug(w.logger(info), "V8 Function call: MutationObserver.disconnect") |
| 75 | + instance, err := w.getInstance(info) |
| 76 | + if err != nil { |
| 77 | + return nil, err |
| 78 | + } |
| 79 | + instance.Disconnect() |
| 80 | + return nil, nil |
| 81 | +} |
| 82 | + |
| 83 | +func (w mutationObserverV8Wrapper) takeRecords(info *v8.FunctionCallbackInfo) (*v8.Value, error) { |
| 84 | + log.Debug(w.logger(info), "V8 Function call: MutationObserver.takeRecords") |
| 85 | + ctx := w.mustGetContext(info) |
| 86 | + instance, err := w.getInstance(info) |
| 87 | + if err != nil { |
| 88 | + return nil, err |
| 89 | + } |
| 90 | + result := instance.TakeRecords() |
| 91 | + return w.toSequenceMutationRecord(ctx, result) |
| 92 | +} |
0 commit comments