Changeset 210149 in webkit for trunk/Source/JavaScriptCore/jsc.cpp
- Timestamp:
- Dec 25, 2016, 10:35:07 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/jsc.cpp
r209906 r210149 1010 1010 static EncodedJSValue JSC_HOST_CALL functionSetRandomSeed(ExecState*); 1011 1011 static EncodedJSValue JSC_HOST_CALL functionIsRope(ExecState*); 1012 static EncodedJSValue JSC_HOST_CALL functionCallerSourceOrigin(ExecState*); 1012 1013 1013 1014 struct Script { … … 1104 1105 { 1105 1106 String str = stringFromUTF(utf8); 1106 return makeSource(str, filename);1107 return makeSource(str, SourceOrigin { filename }, filename); 1107 1108 } 1108 1109 … … 1233 1234 addFunction(vm, "setRandomSeed", functionSetRandomSeed, 1); 1234 1235 addFunction(vm, "isRope", functionIsRope, 1); 1236 addFunction(vm, "callerSourceOrigin", functionCallerSourceOrigin, 0); 1235 1237 1236 1238 addFunction(vm, "is32BitPlatform", functionIs32BitPlatform, 0); … … 1333 1335 } 1334 1336 1335 static bool extractDirectoryName(const String& absolutePathToFile, DirectoryName& directoryName)1337 static std::optional<DirectoryName> extractDirectoryName(const String& absolutePathToFile) 1336 1338 { 1337 1339 size_t firstSeparatorPosition = absolutePathToFile.find(pathSeparator()); 1338 1340 if (firstSeparatorPosition == notFound) 1339 return false; 1341 return std::nullopt; 1342 DirectoryName directoryName; 1340 1343 directoryName.rootName = absolutePathToFile.substring(0, firstSeparatorPosition + 1); // Include the separator. 1341 1344 size_t lastSeparatorPosition = absolutePathToFile.reverseFind(pathSeparator()); … … 1348 1351 directoryName.queryName = absolutePathToFile.substring(queryStartPosition, queryLength); 1349 1352 } 1350 return true;1351 } 1352 1353 static bool currentWorkingDirectory(DirectoryName& directoryName)1353 return directoryName; 1354 } 1355 1356 static std::optional<DirectoryName> currentWorkingDirectory() 1354 1357 { 1355 1358 #if OS(WINDOWS) … … 1365 1368 DWORD bufferLength = ::GetCurrentDirectoryW(0, nullptr); 1366 1369 if (!bufferLength) 1367 return false;1370 return std::nullopt; 1368 1371 // In Windows, wchar_t is the UTF-16LE. 1369 1372 // https://msdn.microsoft.com/en-us/library/dd374081.aspx … … 1375 1378 // We don't support network path like \\host\share\<path name>. 1376 1379 if (directoryString.startsWith("\\\\")) 1377 return false;1380 return std::nullopt; 1378 1381 #else 1379 1382 auto buffer = std::make_unique<char[]>(PATH_MAX); 1380 1383 if (!getcwd(buffer.get(), PATH_MAX)) 1381 return false;1384 return std::nullopt; 1382 1385 String directoryString = String::fromUTF8(buffer.get()); 1383 1386 #endif 1384 1387 if (directoryString.isEmpty()) 1385 return false;1388 return std::nullopt; 1386 1389 1387 1390 if (directoryString[directoryString.length() - 1] == pathSeparator()) 1388 return extractDirectoryName(directoryString , directoryName);1391 return extractDirectoryName(directoryString); 1389 1392 // Append the seperator to represents the file name. extractDirectoryName only accepts the absolute file name. 1390 return extractDirectoryName(makeString(directoryString, pathSeparator()) , directoryName);1393 return extractDirectoryName(makeString(directoryString, pathSeparator())); 1391 1394 } 1392 1395 … … 1434 1437 return deferred->resolve(exec, keyValue); 1435 1438 1436 DirectoryName directoryName;1437 1439 if (referrerValue.isUndefined()) { 1438 if (!currentWorkingDirectory(directoryName)) 1440 auto directoryName = currentWorkingDirectory(); 1441 if (!directoryName) 1439 1442 return deferred->reject(exec, createError(exec, ASCIILiteral("Could not resolve the current working directory."))); 1440 } else { 1441 const Identifier referrer = referrerValue.toPropertyKey(exec); 1442 if (UNLIKELY(scope.exception())) { 1443 JSValue exception = scope.exception(); 1444 scope.clearException(); 1445 return deferred->reject(exec, exception); 1446 } 1447 if (referrer.isSymbol()) { 1448 if (!currentWorkingDirectory(directoryName)) 1449 return deferred->reject(exec, createError(exec, ASCIILiteral("Could not resolve the current working directory."))); 1450 } else { 1451 // If the referrer exists, we assume that the referrer is the correct absolute path. 1452 if (!extractDirectoryName(referrer.impl(), directoryName)) 1453 return deferred->reject(exec, createError(exec, makeString("Could not resolve the referrer name '", String(referrer.impl()), "'."))); 1454 } 1455 } 1456 1457 return deferred->resolve(exec, jsString(exec, resolvePath(directoryName, ModuleName(key.impl())))); 1443 return deferred->resolve(exec, jsString(exec, resolvePath(directoryName.value(), ModuleName(key.impl())))); 1444 } 1445 1446 const Identifier referrer = referrerValue.toPropertyKey(exec); 1447 if (UNLIKELY(scope.exception())) { 1448 JSValue exception = scope.exception(); 1449 scope.clearException(); 1450 return deferred->reject(exec, exception); 1451 } 1452 1453 if (referrer.isSymbol()) { 1454 auto directoryName = currentWorkingDirectory(); 1455 if (!directoryName) 1456 return deferred->reject(exec, createError(exec, ASCIILiteral("Could not resolve the current working directory."))); 1457 return deferred->resolve(exec, jsString(exec, resolvePath(directoryName.value(), ModuleName(key.impl())))); 1458 } 1459 1460 // If the referrer exists, we assume that the referrer is the correct absolute path. 1461 auto directoryName = extractDirectoryName(referrer.impl()); 1462 if (!directoryName) 1463 return deferred->reject(exec, createError(exec, makeString("Could not resolve the referrer name '", String(referrer.impl()), "'."))); 1464 return deferred->resolve(exec, jsString(exec, resolvePath(directoryName.value(), ModuleName(key.impl())))); 1458 1465 } 1459 1466 … … 1946 1953 1947 1954 NakedPtr<Exception> exception; 1948 evaluate(globalObject->globalExec(), makeSource(source ), JSValue(), exception);1955 evaluate(globalObject->globalExec(), makeSource(source, exec->callerSourceOrigin()), JSValue(), exception); 1949 1956 1950 1957 if (exception) { … … 1986 1993 1987 1994 NakedPtr<Exception> evaluationException; 1988 JSValue result = evaluate(globalObject->globalExec(), makeSource(sourceCode ), JSValue(), evaluationException);1995 JSValue result = evaluate(globalObject->globalExec(), makeSource(sourceCode, exec->callerSourceOrigin()), JSValue(), evaluationException); 1989 1996 if (evaluationException) 1990 1997 throwException(exec, scope, evaluationException); … … 2105 2112 const StringImpl* impl = asString(argument)->tryGetValueImpl(); 2106 2113 return JSValue::encode(jsBoolean(!impl)); 2114 } 2115 2116 EncodedJSValue JSC_HOST_CALL functionCallerSourceOrigin(ExecState* state) 2117 { 2118 SourceOrigin sourceOrigin = state->callerSourceOrigin(); 2119 if (sourceOrigin.isNull()) 2120 return JSValue::encode(jsNull()); 2121 return JSValue::encode(jsString(state, sourceOrigin.string())); 2107 2122 } 2108 2123 … … 2405 2420 RETURN_IF_EXCEPTION(scope, encodedJSValue()); 2406 2421 2407 const SourceCode& source = makeSource(functionText );2422 const SourceCode& source = makeSource(functionText, { }); 2408 2423 JSFunction* func = JSFunction::createBuiltinFunction(vm, createBuiltinExecutable(vm, source, Identifier::fromString(&vm, "foo"), ConstructorKind::None, ConstructAbility::CannotConstruct)->link(vm, source), exec->lexicalGlobalObject()); 2409 2424 … … 2429 2444 2430 2445 ParserError error; 2431 bool validSyntax = checkModuleSyntax(exec, makeSource(source, String(), TextPosition(), SourceProviderSourceType::Module), error);2446 bool validSyntax = checkModuleSyntax(exec, makeSource(source, { }, String(), TextPosition(), SourceProviderSourceType::Module), error); 2432 2447 stopWatch.stop(); 2433 2448 … … 2948 2963 auto scope = DECLARE_CATCH_SCOPE(vm); 2949 2964 2950 String interpreterName(ASCIILiteral("Interpreter")); 2965 std::optional<DirectoryName> directoryName = currentWorkingDirectory(); 2966 if (!directoryName) 2967 return; 2968 SourceOrigin sourceOrigin(resolvePath(directoryName.value(), ModuleName("interpreter"))); 2951 2969 2952 2970 bool shouldQuit = false; … … 2963 2981 source = source + line; 2964 2982 source = source + '\n'; 2965 checkSyntax(globalObject->vm(), makeSource(source, interpreterName), error);2983 checkSyntax(globalObject->vm(), makeSource(source, sourceOrigin), error); 2966 2984 if (!line[0]) { 2967 2985 free(line); … … 2979 2997 2980 2998 NakedPtr<Exception> evaluationException; 2981 JSValue returnValue = evaluate(globalObject->globalExec(), makeSource(source, interpreterName), JSValue(), evaluationException);2999 JSValue returnValue = evaluate(globalObject->globalExec(), makeSource(source, sourceOrigin), JSValue(), evaluationException); 2982 3000 #else 2983 3001 printf("%s", interactivePrompt); … … 2994 3012 2995 3013 NakedPtr<Exception> evaluationException; 2996 JSValue returnValue = evaluate(globalObject->globalExec(), jscSource(line, interpreterName), JSValue(), evaluationException);3014 JSValue returnValue = evaluate(globalObject->globalExec(), jscSource(line, sourceOrigin.string()), JSValue(), evaluationException); 2997 3015 #endif 2998 3016 if (evaluationException)
Note:
See TracChangeset
for help on using the changeset viewer.