Closed Bug 779017 Opened 12 years ago Closed 12 years ago

always create ScriptSource

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla17

People

(Reporter: Benjamin, Assigned: Benjamin)

References

Details

Attachments

(1 file)

JSScript's scriptSource_ pointer should never be NULL. If the source is not available, scriptSource_ should just be a shell. Adding the source code should be a different method. This will allow other items that are shared per compilation unit like filename and the source map to be moved to the ScriptSource struct.
Assignee: general → bpeterson
Attachment #647397 - Flags: review?(jorendorff)
Blocks: 779233
Comment on attachment 647397 [details] [diff] [review] give every script a ScriptSource Review of attachment 647397 [details] [diff] [review]: ----------------------------------------------------------------- Looks good except for a few nits. r=me with those fixed. ::: js/src/frontend/BytecodeCompiler.cpp @@ +245,5 @@ > { > if (!CheckLength(cx, length)) > return false; > + ScriptSource *ss = cx->new_<ScriptSource>(); > + AutoAttachToRuntime attacher(cx->runtime, ss); CompileScript() checks for null ss. This should too. ::: js/src/jsscript.cpp @@ +1243,3 @@ > if (!ownSource) { > const size_t nbytes = length * sizeof(jschar); > + data.compressed = static_cast<unsigned char *>(cx->runtime->malloc_(nbytes)); Instead use cx->malloc_(nbytes) which reports the error on failure. @@ +1363,4 @@ > return false; > } > + if (!xdr->codeBytes(data.compressed, byteLen)) { > + xdr->cx()->free_(data.compressed); This should only free this memory if we allocated it in the first place (that is, if mode is XDR_DECODE). Also: if we are decoding, it should probably return length_, compressedLength_, and data.compressed to a consistent state before returning, right? (This ScriptSource is already attached to a script, I think, so it'll be destroyed eventually.) Maybe this can be rewritten to first decode to local variables, then call setSource() only on success.
Attachment #647397 - Flags: review?(jorendorff) → review+
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla17
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: