epub-cfi-generator
Version:
Generates CFI for each text node in each spine for given EPUB
74 lines (49 loc) • 2.39 kB
JavaScript
/*jshint globalstrict: true*/
;
var EPUBcfi = {
};
// Description: This is a set of runtime errors that the CFI interpreter can throw.
// Rationale: These error types extend the basic javascript error object so error things like the stack trace are
// included with the runtime errors.
// REFACTORING CANDIDATE: This type of error may not be required in the long run. The parser should catch any syntax errors,
// provided it is error-free, and as such, the AST should never really have any node type errors, which are essentially errors
// in the structure of the AST. This error should probably be refactored out when the grammar and interpreter are more stable.
EPUBcfi.NodeTypeError = function (node, message) {
function NodeTypeError () {
this.node = node;
}
NodeTypeError.prototype = new Error(message);
NodeTypeError.constructor = NodeTypeError;
return new NodeTypeError();
};
// REFACTORING CANDIDATE: Might make sense to include some more specifics about the out-of-rangeyness.
EPUBcfi.OutOfRangeError = function (targetIndex, maxIndex, message) {
function OutOfRangeError () {
this.targetIndex = targetIndex;
this.maxIndex = maxIndex;
}
OutOfRangeError.prototype = new Error(message);
OutOfRangeError.constructor = new OutOfRangeError();
return new OutOfRangeError();
};
// REFACTORING CANDIDATE: This is a bit too general to be useful. When I have a better understanding of the type of errors
// that can occur with the various terminus conditions, it'll make more sense to revisit this.
EPUBcfi.TerminusError = function (terminusType, terminusCondition, message) {
function TerminusError () {
this.terminusType = terminusType;
this.terminusCondition = terminusCondition;
}
TerminusError.prototype = new Error(message);
TerminusError.constructor = new TerminusError();
return new TerminusError();
};
EPUBcfi.CFIAssertionError = function (expectedAssertion, targetElementAssertion, message) {
function CFIAssertionError () {
this.expectedAssertion = expectedAssertion;
this.targetElementAssertion = targetElementAssertion;
}
CFIAssertionError.prototype = new Error(message);
CFIAssertionError.constructor = new CFIAssertionError();
return new CFIAssertionError();
};
exports.EPUBcfi = EPUBcfi;