Skip to content

Commit

Permalink
Modifying config used by a parser should throw.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrv committed Mar 6, 2018
1 parent 4a92df7 commit 98ad6f0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/parser/ParserConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class ParserConfig {
}

unlink() {
if(this.isFrozen) throw('Cannot modify config object used by a parser.');
if(!this.isLinked) return;
this.isLinked = false;

Expand Down Expand Up @@ -139,6 +140,8 @@ export class ParserConfig {
const nativeParser = new NativeParser(this.native);
const config = new ParserConfig(this, nativeParser.getConfig());

this.isFrozen = true;

return(new Parser(config, nativeParser));
}

Expand All @@ -157,7 +160,7 @@ export class ParserConfig {

if(nsParser) return(nsParser.id);

if(this.isLinked) this.unlink();
this.unlink();

nsBase.uri = uri;
nsParser = new ParserNamespace(nsBase, this);
Expand All @@ -177,7 +180,7 @@ export class ParserConfig {
bindNamespace(nsBase: Namespace, prefix?: string, parser?: Parser) {
this.addNamespace(nsBase);

let uri = nsBase.uri;
let uri = (this.nsMapper && this.nsMapper(nsBase.uri)) || nsBase.uri;
let nsParser = this.namespaceTbl[uri];

if(!prefix && prefix != '') prefix = nsParser.base.defaultPrefix;
Expand All @@ -204,7 +207,7 @@ export class ParserConfig {
}

addUri(uri: string, ns: ParserNamespace) {
if(this.isLinked) this.unlink();
this.unlink();

const token = this.uriSet.createToken(uri);

Expand All @@ -215,7 +218,7 @@ export class ParserConfig {
}

addPrefix(prefix: string) {
if(this.isLinked) this.unlink();
this.unlink();

const token = this.prefixSet.createToken(prefix);

Expand Down Expand Up @@ -296,8 +299,10 @@ export class ParserConfig {
return(this.namespaceList[id].addAttribute(name).tokenList);
}

/** If false, object is a clone sharing data with a parent object. */
/** If true, object is a clone sharing data with a parent object. */
private isLinked: boolean;
/** If true, another object is a clone sharing data with this object. */
private isFrozen: boolean;

/** Reference to C++ object. */
private native: NativeConfig;
Expand Down

0 comments on commit 98ad6f0

Please sign in to comment.