Closed Bug 1734101 Opened 4 years ago Closed 4 years ago

Encode/decode ScriptSource options

Categories

(Core :: JavaScript Engine, task, P1)

task

Tracking

()

RESOLVED FIXED
95 Branch
Tracking Status
firefox95 --- fixed

People

(Reporter: arai, Assigned: arai)

References

Details

Attachments

(1 file)

when decoding Stencil XDR, ScriptSource is initialized from ReadOnlyCompileOptions fields, but those information should be known from the original stencil used while encoding.
to introduce subset of CompileOptions in bug 1726498, we should remove the dependency to ReadOnlyCompileOptions there.

https://searchfox.org/mozilla-central/rev/9bc5dcea99c59dc18eae0de7064131aa20cfbb66/js/src/vm/JSScript.cpp#2212

template <XDRMode mode>
/* static */
XDRResult ScriptSource::XDR(XDRState<mode>* xdr,
                            const ReadOnlyCompileOptions* maybeOptions,
                            RefPtr<ScriptSource>& source) {
  JSContext* cx = xdr->cx();

  if (mode == XDR_DECODE) {
...
    if (!source->initFromOptions(cx, *maybeOptions)) {
      return xdr->fail(JS::TranscodeResult::Throw);
    }

https://searchfox.org/mozilla-central/rev/9bc5dcea99c59dc18eae0de7064131aa20cfbb66/js/src/vm/JSScript.cpp#2321-2359

bool ScriptSource::initFromOptions(JSContext* cx,
                                   const ReadOnlyCompileOptions& options) {
  MOZ_ASSERT(!filename_);
  MOZ_ASSERT(!introducerFilename_);

  mutedErrors_ = options.mutedErrors();

  startLine_ = options.lineno;
  introductionType_ = options.introductionType;
  setIntroductionOffset(options.introductionOffset);
  // The parameterListEnd_ is initialized later by setParameterListEnd, before
  // we expose any scripts that use this ScriptSource to the debugger.

  if (options.hasIntroductionInfo) {
    MOZ_ASSERT(options.introductionType != nullptr);
    const char* filename =
        options.filename() ? options.filename() : "<unknown>";
    UniqueChars formatted = FormatIntroducedFilename(
        cx, filename, options.introductionLineno, options.introductionType);
    if (!formatted) {
      return false;
    }
    if (!setFilename(cx, std::move(formatted))) {
      return false;
    }
  } else if (options.filename()) {
    if (!setFilename(cx, options.filename())) {
      return false;
    }
  }

  if (options.introducerFilename()) {
    if (!setIntroducerFilename(cx, options.introducerFilename())) {
      return false;
    }
  }

  return true;
}
Severity: -- → N/A
Priority: -- → P1

due to ScriptSource.introductionType_ field's "statically allocated C string" requirement, we cannot encode/decode it.
JS::DecodeOptions needs the field.

other fields can be encoded/decoded.

Depends on: 1737144
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/811bc98b7334 Encode/decode more ScriptSource fields. r=tcampbell
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 95 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: