Exemplo n.º 1
0
bool
Preprocessor::enterFile(TokenKind directive,
                        const SourceLocation &from,
                        const char *file,
                        const char *where)
{
  if (disable_includes_)
    return false;

  AutoString path = searchPaths(file, where);
  if (!path.length()) {
    // Try to append '.inc'.
    size_t len = strlen(file);
    if (len < 4 || strcmp(&file[len - 4], ".inc") != 0) {
      AutoString new_file = AutoString(file) + ".inc";
      path = searchPaths(new_file, where);
    }
  }

  if (!path.length()) {
    if (directive == TOK_M_TRYINCLUDE)
      return true;

    cc_.report(from, rmsg::include_not_found)
      << file;
    return false;
  }

  ReportingContext rc(cc_, from);
  Ref<SourceFile> new_file = cc_.source().open(rc, path.ptr());
  if (!new_file)
    return false;

  LREntry tl = cc_.source().trackFile(from, new_file);
  if (!tl.valid()) {
    // Error was already reported.
    return false;
  }

  if (include_depth_ >= kMaxIncludeDepth) {
    cc_.report(from, rmsg::include_depth_exceeded);
    return false;
  }

  include_depth_++;

  assert(!macro_lexer_ && lexer_);
  lexer_stack_.append(SavedLexer(lexer_, nullptr));
  lexer_ = new Lexer(cc_, *this, lexer_->options(), new_file, tl);
  return true;
}
Exemplo n.º 2
0
bool
Library::Name(JSContext* cx, unsigned argc, Value* vp)
{
  CallArgs args = CallArgsFromVp(argc, vp);
  if (args.length() != 1) {
    JS_ReportErrorASCII(cx, "libraryName takes one argument");
    return false;
  }

  Value arg = args[0];
  JSString* str = nullptr;
  if (arg.isString()) {
    str = arg.toString();
  } else {
    JS_ReportErrorASCII(cx, "name argument must be a string");
    return false;
  }

  AutoString resultString;
  AppendString(resultString, DLL_PREFIX);
  AppendString(resultString, str);
  AppendString(resultString, DLL_SUFFIX);

  JSString* result = JS_NewUCStringCopyN(cx, resultString.begin(),
                                         resultString.length());
  if (!result)
    return false;

  args.rval().setString(result);
  return true;
}
Exemplo n.º 3
0
JSBool
Library::Name(JSContext* cx, uintN argc, jsval *vp)
{
  if (argc != 1) {
    JS_ReportError(cx, "libraryName takes one argument");
    return JS_FALSE;
  }

  jsval arg = JS_ARGV(cx, vp)[0];
  JSString* str = NULL;
  if (JSVAL_IS_STRING(arg)) {
    str = JSVAL_TO_STRING(arg);
  }
  else {
    JS_ReportError(cx, "name argument must be a string");
      return JS_FALSE;
  }

  AutoString resultString;
  AppendString(resultString, DLL_PREFIX);
  AppendString(resultString, str);
  AppendString(resultString, DLL_SUFFIX);

  JSString *result = JS_NewUCStringCopyN(cx, resultString.begin(),
                                         resultString.length());
  if (!result)
    return JS_FALSE;

  JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(result));
  return JS_TRUE;
}