Skip to content

Commit

Permalink
Reference extension instead of using a variable scope in ExtensionFie…
Browse files Browse the repository at this point in the history
…ld, see #161
  • Loading branch information
dcodeIO committed Aug 24, 2014
1 parent 64b7a2b commit 267253c
Show file tree
Hide file tree
Showing 34 changed files with 171 additions and 245 deletions.
23 changes: 11 additions & 12 deletions dist/ProtoBuf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2438,13 +2438,6 @@
return $1.toUpperCase();
});
}

/**
* Scope used to resolve the type.
* @type {!ProtoBuf.Reflect.Message}
* @expose
*/
this.scope = message;
};

// Extends T
Expand Down Expand Up @@ -3005,6 +2998,13 @@
*/
var ExtensionField = function(message, rule, type, name, id, options) {
Field.call(this, message, rule, type, name, id, options);

/**
* Extension reference.
* @type {!ProtoBuf.Reflect.Extension}
* @expose
*/
this.extension;
};

// Extends Field
Expand Down Expand Up @@ -3655,12 +3655,11 @@
throw Error("Duplicate extended field id in message "+obj.name+": "+def['fields'][i]['id']);
if (def['fields'][i]['id'] < obj.extensions[0] || def['fields'][i]['id'] > obj.extensions[1])
throw Error("Illegal extended field id in message "+obj.name+": "+def['fields'][i]['id']+" ("+obj.extensions.join(' to ')+" expected)");
// see #161: Extensions use their fully qualified name as their runtime key, ...
// see #161: Extensions use their fully qualified name as their runtime key and...
var fld = new Reflect.Message.ExtensionField(obj, def["fields"][i]["rule"], def["fields"][i]["type"], this.ptr.fqn()+'.'+def["fields"][i]["name"], def["fields"][i]["id"], def["fields"][i]["options"]);
// ...are added on top of the current namespace as an extension and...
// ...are added on top of the current namespace as an extension which is used for resolving their type later on
var ext = new Reflect.Extension(this.ptr, def["fields"][i]["name"], fld);
// ...use the current namespace to resolve types.
fld.scope = this.ptr;
fld.extension = ext;
this.ptr.addChild(ext);
obj.addChild(fld);
}
Expand Down Expand Up @@ -3837,7 +3836,7 @@
if (!Lang.TYPE.test(this.ptr.type)) { // Resolve type...
if (!Lang.TYPEREF.test(this.ptr.type))
throw Error("Illegal type reference in "+this.ptr.toString(true)+": "+this.ptr.type);
res = this.ptr.scope.resolve(this.ptr.type, true); // this.ptr.parent
res = (this.ptr instanceof Reflect.Message.ExtensionField ? this.ptr.extension.parent : this.ptr.parent).resolve(this.ptr.type, true);
if (!res)
throw Error("Unresolvable type reference in "+this.ptr.toString(true)+": "+this.ptr.type);
this.ptr.resolvedType = res;
Expand Down
29 changes: 15 additions & 14 deletions dist/ProtoBuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/ProtoBuf.min.js.gz
Binary file not shown.
6 changes: 3 additions & 3 deletions dist/ProtoBuf.min.map

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions dist/ProtoBuf.noparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1568,13 +1568,6 @@
return $1.toUpperCase();
});
}

/**
* Scope used to resolve the type.
* @type {!ProtoBuf.Reflect.Message}
* @expose
*/
this.scope = message;
};

// Extends T
Expand Down Expand Up @@ -2135,6 +2128,13 @@
*/
var ExtensionField = function(message, rule, type, name, id, options) {
Field.call(this, message, rule, type, name, id, options);

/**
* Extension reference.
* @type {!ProtoBuf.Reflect.Extension}
* @expose
*/
this.extension;
};

// Extends Field
Expand Down Expand Up @@ -2785,12 +2785,11 @@
throw Error("Duplicate extended field id in message "+obj.name+": "+def['fields'][i]['id']);
if (def['fields'][i]['id'] < obj.extensions[0] || def['fields'][i]['id'] > obj.extensions[1])
throw Error("Illegal extended field id in message "+obj.name+": "+def['fields'][i]['id']+" ("+obj.extensions.join(' to ')+" expected)");
// see #161: Extensions use their fully qualified name as their runtime key, ...
// see #161: Extensions use their fully qualified name as their runtime key and...
var fld = new Reflect.Message.ExtensionField(obj, def["fields"][i]["rule"], def["fields"][i]["type"], this.ptr.fqn()+'.'+def["fields"][i]["name"], def["fields"][i]["id"], def["fields"][i]["options"]);
// ...are added on top of the current namespace as an extension and...
// ...are added on top of the current namespace as an extension which is used for resolving their type later on
var ext = new Reflect.Extension(this.ptr, def["fields"][i]["name"], fld);
// ...use the current namespace to resolve types.
fld.scope = this.ptr;
fld.extension = ext;
this.ptr.addChild(ext);
obj.addChild(fld);
}
Expand Down Expand Up @@ -2967,7 +2966,7 @@
if (!Lang.TYPE.test(this.ptr.type)) { // Resolve type...
if (!Lang.TYPEREF.test(this.ptr.type))
throw Error("Illegal type reference in "+this.ptr.toString(true)+": "+this.ptr.type);
res = this.ptr.scope.resolve(this.ptr.type, true); // this.ptr.parent
res = (this.ptr instanceof Reflect.Message.ExtensionField ? this.ptr.extension.parent : this.ptr.parent).resolve(this.ptr.type, true);
if (!res)
throw Error("Unresolvable type reference in "+this.ptr.toString(true)+": "+this.ptr.type);
this.ptr.resolvedType = res;
Expand Down
Loading

0 comments on commit 267253c

Please sign in to comment.